Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong-type-argument integer-or-marker-p nil #1074

Closed
bbigras opened this issue Aug 28, 2020 · 10 comments
Closed

wrong-type-argument integer-or-marker-p nil #1074

bbigras opened this issue Aug 28, 2020 · 10 comments

Comments

@bbigras
Copy link

bbigras commented Aug 28, 2020

Description

One weird thing is that I only seems to have this error when using envrc.

Steps to Reproduce

Not sure yet. I'll try to get a minimal example if it's not a trivial fix.

Backtrace

Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
  buffer-substring-no-properties(nil nil)
  #f(compiled-function (link) #<bytecode -0x1034ece9f6ae52bc>)((link (:type "https" :path "//www.sciencedaily.com/releases/2019/07/1907191735..." :format bracket :raw-link "https://www.sciencedaily.com/releases/2019/07/1907..." :application nil :search-option nil :begin 2 :end 127 :contents-begin 68 :contents-end 125 :post-blank 0 :parent (paragraph (:begin 2 :end 128 :contents-begin 2 :contents-end 128 :post-blank 0 :post-affiliated 2 :parent (section (:begin 2 :end 128 :contents-begin 2 :contents-end 128 :post-blank 0 :post-affiliated 2 :parent (org-data nil #43)) #27)) #1 #("\n" 0 1 (:parent #27)))) #("Take a bath 90 minutes before bedtime to get bette..." 0 57 (:parent #1))))
  #f(compiled-function (--data) #<bytecode -0xd4d286dd6ac900a>)((link (:type "https" :path "//www.sciencedaily.com/releases/2019/07/1907191735..." :format bracket :raw-link "https://www.sciencedaily.com/releases/2019/07/1907..." :application nil :search-option nil :begin 2 :end 127 :contents-begin 68 :contents-end 125 :post-blank 0 :parent (paragraph (:begin 2 :end 128 :contents-begin 2 :contents-end 128 :post-blank 0 :post-affiliated 2 :parent (section (:begin 2 :end 128 :contents-begin 2 :contents-end 128 :post-blank 0 :post-affiliated 2 :parent (org-data nil #43)) #27)) #1 #("\n" 0 1 (:parent #27)))) #("Take a bath 90 minutes before bedtime to get bette..." 0 57 (:parent #1))))
  mapc(#f(compiled-function (--data) #<bytecode -0xd4d286dd6ac900a>) ((link (:type "https" :path "//www.sciencedaily.com/releases/2019/07/1907191735..." :format bracket :raw-link "https://www.sciencedaily.com/releases/2019/07/1907..." :application nil :search-option nil :begin 2 :end 127 :contents-begin 68 :contents-end 125 :post-blank 0 :parent (paragraph (:begin 2 :end 128 :contents-begin 2 :contents-end 128 :post-blank 0 :post-affiliated 2 :parent (section (:begin 2 :end 128 :contents-begin 2 :contents-end 128 :post-blank 0 :post-affiliated 2 :parent ...) #29)) . #2)) #("Take a bath 90 minutes before bedtime to get bette..." 0 57 (:parent #3))) #("\n" 0 1 (:parent (paragraph (:begin 2 :end 128 :contents-begin 2 :contents-end 128 :post-blank 0 :post-affiliated 2 :parent (section (:begin 2 :end 128 :contents-begin 2 :contents-end 128 :post-blank 0 :post-affiliated 2 :parent ...) #7)) . #2)))))
  #f(compiled-function (--data) #<bytecode -0xd4d286dd6ac900a>)((paragraph (:begin 2 :end 128 :contents-begin 2 :contents-end 128 :post-blank 0 :post-affiliated 2 :parent (section (:begin 2 :end 128 :contents-begin 2 :contents-end 128 :post-blank 0 :post-affiliated 2 :parent (org-data nil #17)) #1)) (link (:type "https" :path "//www.sciencedaily.com/releases/2019/07/1907191735..." :format bracket :raw-link "https://www.sciencedaily.com/releases/2019/07/1907..." :application nil :search-option nil :begin 2 :end 127 :contents-begin 68 :contents-end 125 :post-blank 0 :parent #1) #("Take a bath 90 minutes before bedtime to get bette..." 0 57 (:parent #4))) #("\n" 0 1 (:parent #1))))
  mapc(#f(compiled-function (--data) #<bytecode -0xd4d286dd6ac900a>) ((paragraph (:begin 2 :end 128 :contents-begin 2 :contents-end 128 :post-blank 0 :post-affiliated 2 :parent (section (:begin 2 :end 128 :contents-begin 2 :contents-end 128 :post-blank 0 :post-affiliated 2 :parent (org-data nil #19)) . #2)) (link (:type "https" :path "//www.sciencedaily.com/releases/2019/07/1907191735..." :format bracket :raw-link "https://www.sciencedaily.com/releases/2019/07/1907..." :application nil :search-option nil :begin 2 :end 127 :contents-begin 68 :contents-end 125 :post-blank 0 :parent #3) #("Take a bath 90 minutes before bedtime to get bette..." 0 57 (:parent #6))) #("\n" 0 1 (:parent #3)))))
  #f(compiled-function (--data) #<bytecode -0xd4d286dd6ac900a>)((section (:begin 2 :end 128 :contents-begin 2 :contents-end 128 :post-blank 0 :post-affiliated 2 :parent (org-data nil #1)) (paragraph (:begin 2 :end 128 :contents-begin 2 :contents-end 128 :post-blank 0 :post-affiliated 2 :parent #1) (link (:type "https" :path "//www.sciencedaily.com/releases/2019/07/1907191735..." :format bracket :raw-link "https://www.sciencedaily.com/releases/2019/07/1907..." :application nil :search-option nil :begin 2 :end 127 :contents-begin 68 :contents-end 125 :post-blank 0 :parent #4) #("Take a bath 90 minutes before bedtime to get bette..." 0 57 (:parent #7))) #("\n" 0 1 (:parent #4)))))
  mapc(#f(compiled-function (--data) #<bytecode -0xd4d286dd6ac900a>) ((section (:begin 2 :end 128 :contents-begin 2 :contents-end 128 :post-blank 0 :post-affiliated 2 :parent (org-data nil . #2)) (paragraph (:begin 2 :end 128 :contents-begin 2 :contents-end 128 :post-blank 0 :post-affiliated 2 :parent #3) (link (:type "https" :path "//www.sciencedaily.com/releases/2019/07/1907191735..." :format bracket :raw-link "https://www.sciencedaily.com/releases/2019/07/1907..." :application nil :search-option nil :begin 2 :end 127 :contents-begin 68 :contents-end 125 :post-blank 0 :parent #6) #("Take a bath 90 minutes before bedtime to get bette..." 0 57 (:parent #9))) #("\n" 0 1 (:parent #6))))))
  #f(compiled-function (--data) #<bytecode -0xd4d286dd6ac900a>)((org-data nil (section (:begin 2 :end 128 :contents-begin 2 :contents-end 128 :post-blank 0 :post-affiliated 2 :parent #1) (paragraph (:begin 2 :end 128 :contents-begin 2 :contents-end 128 :post-blank 0 :post-affiliated 2 :parent #4) (link (:type "https" :path "//www.sciencedaily.com/releases/2019/07/1907191735..." :format bracket :raw-link "https://www.sciencedaily.com/releases/2019/07/1907..." :application nil :search-option nil :begin 2 :end 127 :contents-begin 68 :contents-end 125 :post-blank 0 :parent #7) #("Take a bath 90 minutes before bedtime to get bette..." 0 57 (:parent #10))) #("\n" 0 1 (:parent #7))))))
  org-element-map((org-data nil (section (:begin 2 :end 128 :contents-begin 2 :contents-end 128 :post-blank 0 :post-affiliated 2 :parent #1) (paragraph (:begin 2 :end 128 :contents-begin 2 :contents-end 128 :post-blank 0 :post-affiliated 2 :parent #4) (link (:type "https" :path "//www.sciencedaily.com/releases/2019/07/1907191735..." :format bracket :raw-link "https://www.sciencedaily.com/releases/2019/07/1907..." :application nil :search-option nil :begin 2 :end 127 :contents-begin 68 :contents-end 125 :post-blank 0 :parent #7) #("Take a bath 90 minutes before bedtime to get bette..." 0 57 (:parent #10))) #("\n" 0 1 (:parent #7))))) link #f(compiled-function (link) #<bytecode -0x1034ece9f6ae52bc>))
  org-roam--extract-links("/home/bbigras/.dropbox-hm/Dropbox/org-mode/notes/s...")
  org-roam-db-build-cache()
  org-roam-mode()
  run-hooks(after-init-hook delayed-warnings-hook)
  command-line()
  normal-top-level()

Expected Results

Actual Results

Environment

  • Emacs: GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.21, cairo version 1.16.0)
  • Framework: N/A
  • Org: Org mode version 9.3.7 (9.3.7-22-gbd9785-elpa @ /nix/store/918j48h02krnyhh1rb3w6rawhaazzhhd-emacs-packages-deps/share/emacs/site-lisp/elpa/org-20200824/)
  • Org-roam: 1.2.1
@spacekitteh
Copy link
Contributor

spacekitteh commented Aug 29, 2020

I started getting this issue yesterday, too. Happens on both gccemacs and master. I'm using Nix too. I'm not using envrc

@jethrokuan
Copy link
Member

can you share a minimally reproducible Org file?

@spacekitteh
Copy link
Contributor

This does it for me:


* Countable
  :PROPERTIES:
  :ID:       5c82ce3f-5868-4dc7-8801-e0436757b7c3
  :END:
  :RESOURCES:
  - [[file:persistence-diagram.org::* Footnotes][Footnotes]]
  :END:
  

When I remove the final ] of the link to the footnotes headline, it fucks up.

@spacekitteh
Copy link
Contributor

Since that :RESOURCES: was created, I have since added an ID property to the linked Footnotes section.

@spacekitteh
Copy link
Contributor

So, it happened in two files for me: Neither had a #+TITLE, and both had a :RESOURCES: drawer with a link in it. One of the files was literally just a :RESOURCES: drawer with a single link.

@jethrokuan
Copy link
Member

With the following file contents:

* Countable
  :PROPERTIES:
  :ID:       5c82ce3f-5868-4dc7-8801-e0436757b7c3
  :END:
  :RESOURCES:
  - [[file:persistence-diagram.org::* Footnotes][Footnotes]]
  :END:
(["/home/jethro/Nextcloud/org/braindump/org/lit/countable.org" "persistence-diagram.org" "file" (:outline ("Countable") :content ":RESOURCES:
  - [[file:persistence-diagram.org::* Footnotes][Footnotes]
  :END:" :point 86)])

(org-roam--extract-links) gives the right values on current master (9ff57c8, with or without the final ].

@kisaragi-hiu
Copy link
Contributor

kisaragi-hiu commented Sep 2, 2020

This is probably caused by the leading whitespaces (and org-element-at-point).

Reproduction

/tmp/test.org (the leading blank line is what triggers it):


#+title: title
content
[[file:/home/]]

Run (org-roam--extract-links), and the same error will appear.

Why

org-element-at-point apparently returns nil "within blank lines at the beginning of buffer", as shown in this excerpt (context)

   (let ((origin (point)))
     (end-of-line)
     (skip-chars-backward " \r\t\n")
     (cond
      ;; Within blank lines at the beginning of buffer, return nil.
      ((bobp) nil)
  ;; ...

then org-roam--extract-links ends up sending the nil to buffer-substring-no-properties, sending the error.

Solution

An extra (org-skip-whitespace) needs to be added before (org-element-at-point).

jethrokuan added a commit that referenced this issue Sep 4, 2020
Fixes #1082, #1077, #1074

When reverting link extraction to using the `org-element` api, the
preview content (org-element-at-point) was incorrectly extracted,
causing incorrect preview content and cryptic messages.
jethrokuan added a commit that referenced this issue Sep 4, 2020
Fixes #1082, #1077, #1074

When reverting link extraction to using the `org-element` api, the
preview content (org-element-at-point) was incorrectly extracted,
causing incorrect preview content and cryptic messages.
@jethrokuan
Copy link
Member

Should be fixed with the recent changes.

@d12frosted
Copy link
Contributor

d12frosted commented Oct 9, 2020

🤔 started to get this error yesterday after update to the latest version. Don't have leading newlines in the linked files. I've run org-roam-doctor in note with link and offending note, but everything was fine according to doctor.

I tried to debug it and it seems that it fails here:

                 (content (or (org-element-property :raw-value element)
                              (buffer-substring-no-properties
                               begin
                               (or (org-element-property :content-end element)
                                   (org-element-property :end element)))))

I saw that my element is missing :content-begin and :content-end, but :contents-begin and :contents-end are present. I could not find relevant changes in the org-mode (though I didn't spend much time there), so I simply modified function definition like this:

(defun org-roam--extract-links (&optional file-path)
  "Extracts all link items within the current buffer.
Link items are of the form:

    [from to type properties]

This is the format that emacsql expects when inserting into the database.
FILE-FROM is typically the buffer file path, but this may not exist, for example
in temp buffers.  In cases where this occurs, we do know the file path, and pass
it as FILE-PATH."
  (require 'org-ref nil t)
  (setq file-path (or file-path
                      org-roam-file-name
                      (buffer-file-name)))
  (save-excursion
    (let (links)
      (org-element-map (org-element-parse-buffer) 'link
        (lambda (link)
          (goto-char (org-element-property :begin link))
          (when-let* ((type (org-roam--collate-types (org-element-property :type link)))
                      (path (org-element-property :path link))
                      (element (org-element-at-point))
                      (begin (or (org-element-property :content-begin element)
                                 (org-element-property :contents-begin element)
                                 (org-element-property :begin element)))
                      (content (or (org-element-property :raw-value element)
                                   (buffer-substring-no-properties
                                    begin
                                    (or (org-element-property :content-end element)
                                        (org-element-property :contents-end element)
                                        (org-element-property :end element)))))
                      (content (string-trim content))
                      (properties (list :outline (org-roam--get-outline-path)
                                        :content content
                                        :point begin))
                      (names (pcase type
                               ("id"
                                (list (car (org-roam-id-find path))))
                               ("cite" (list path))
                               ("website" (list path))
                               ("fuzzy" (list path))
                               ("roam" (list path))
                               (_ (if (or (file-remote-p path)
                                          (org-roam--url-p path))
                                      (list path)
                                    (let ((file-maybe (expand-file-name path (file-name-directory file-path))))
                                      (if (f-exists? file-maybe)
                                          (list file-maybe)
                                        (list path))))))))
            (dolist (name names)
              (when name
                (push (vector file-path name type properties) links))))))
      links)))

And now it seems to be working. Please notice that I also changed let* to when-let* because element was nil sometimes. 🤷 If you wish, I can send it as PR. Actually sent it, and we can discuss solution there: #1176

@d12frosted
Copy link
Contributor

🤔 according to Elements API, the name for this property is contents-begin and contents-end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants