ahungry / org-jira

Bring Jira and OrgMode together
680 stars 130 forks source link

Error in org-jira-get-issues: Calling org-fold-core-region with missing SPEC #326

Closed ckonstanski-olo closed 1 year ago

ckonstanski-olo commented 1 year ago

GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo version 1.17.8, Xaw3d scroll bars) of 2023-05-27

org-jira-20230413.441

When running org-jira-get-issues the following error occurs. I'm no elisp expert, but I think that the function org-fold-core-folding-spec-list fails to return a folding spec for the buffer.

(defsubst org-fold-core-folding-spec-list (&optional buffer)
  "Return list of all the folding spec symbols in BUFFER."
  (or (buffer-local-value 'org-fold-core--spec-list (or buffer (current-buffer)))
      (with-current-buffer (or buffer (current-buffer))
        (setq org-fold-core--spec-list (mapcar #'car org-fold-core--specs)))))

The stacktrace:

Debugger entered--Lisp error: (error "Calling ‘org-fold-core-region’ with missing SPEC")
  signal(error ("Calling ‘org-fold-core-region’ with missing SPEC"))
  error("Calling `org-fold-core-region' with missing SPEC")
  org-fold-region(1409 1415 t outline)
  org-insert-property-drawer()
  org-get-property-block(1319 force)
  org-entry-put(1383 "assignee" "Carlos Konstanski")
  org-jira-entry-put(1383 "assignee" "Carlos Konstanski")
  org-jira--render-issue(#<org-jira-sdk-issue org-jira-sdk-issue-156a3ca91e00>)
  mapc(org-jira--render-issue (#<org-jira-sdk-issue org-jira-sdk-issue-156a3ca91e00> ...))
  org-jira--render-issues-from-issue-list((#<org-jira-sdk-issue org-jira-sdk-issue-156a3ca91e00> ...))
  org-jira-get-issues((#<org-jira-sdk-issue org-jira-sdk-issue-156a3ca91e00> ...))
  #f(compiled-function (&rest rest) "Callback for async, DATA is the response from the request call.\n\nWill send a list of org-jira-sdk-issue objects to the list printer." #<bytecode 0x155bd04851c94e33>)(:data (... ... ... ... ...) :symbol-status success :error-thrown nil :response #s(request-response :status-code 200 :history nil :data ... :error-thrown nil :symbol-status success :url "https://ololab..." :done-p nil :settings ... :-buffer #<killed buffer> :-raw-header "HTTP/2 200 \nda..." :-timer nil :-backend curl))
  apply(#f(compiled-function (&rest rest) "Callback for async, DATA is the response from the request call.\n\nWill send a list of org-jira-sdk-issue objects to the list printer." #<bytecode 0x155bd04851c94e33>) (:data ... :symbol-status success :error-thrown nil :response ...))
  request--callback(#<killed buffer> :sync nil :headers (... ...) :parser jiralib--json-read :complete #f(compiled-function (&rest rest) "Callback for async, DATA is the response from the request call.\n\nWill send a list of org-jira-sdk-issue objects to the list printer." #<bytecode 0x155bd04851c94e33>) :error (lambda ... "\n\n(fn &key DAT..." ...) :type "POST" :data ...)
  apply(request--callback #<killed buffer> (:sync nil :headers (("Authorization" . "Basic Y2FybG9zLmtvbnN0YW5z...") ("Content-Type" . "application/json")) :parser jiralib--json-read :complete #f(compiled-function (&rest rest) "Callback for async, DATA is the response from the request call.\n\nWill send a list of org-jira-sdk-issue objects to the list printer." #<bytecode 0x155bd04851c94e33>) :error (lambda (&rest --cl-rest--) "\n\n(fn &key DATA &allow-oth..." (apply ... ... ... --cl-rest--)) :type "POST" :data "{\"jql\":\"assignee = current..." :url "https://ololabs.atlassian...." :response #s(request-response :status-code 200 :history nil :data (... ... ... ... ...) :error-thrown nil :symbol-status success :url "https://ololabs.atlassian...." :done-p nil :settings #3 :-buffer #<killed buffer> :-raw-header "HTTP/2 200 \ndate: Sun, 28 ..." :-timer nil :-backend curl) :encoding utf-8))
  request--curl-callback("https://ololabs.atlassian.net/rest/api/2/search" #<process request curl<99>> "finished\n")
  apply(request--curl-callback ("https://ololabs.atlassian.net/rest/api/2/search" #<process request curl<99>> "finished\n"))
  #f(compiled-function (&rest args2) #<bytecode -0x190ba810c79ff01c>)(#<process request curl<99>> "finished\n")
ckonstanski-olo commented 1 year ago

I familiarized myself with the edebug debugger. I set a breakpoint at the beginning of function org-fold-core-get-folding-spec-from-alias. It ran quite a few times successfully. Every time the input argument spec-or-alias had one of these values: "org-fold-visible" or "org-fold-hidden". But then the function ran with a value of "drawer", and that's when it returned nil and the error was thrown higher up in org-fold-core-region when it explicitly tests for a nil result.

Perhaps I need to add an entry in org-fold-core--spec-symbols for "drawer". Looking for something appropriate.

ckonstanski-olo commented 1 year ago

org-fold-core--spec-symbols has the value:

((hidden . org-fold-hidden) (:alias . org-fold-hidden) (org-fold-hidden . org-fold-hidden) (visible . org-fold-visible) (:alias . org-fold-visible) (org-fold-visible . org-fold-visible))

But when a drawer wants to be added we call org-fold-core-get-folding-spec-from-alias like this:

(org-fold-region (line-end-position 0) (point) t (if (eq org-fold-core-style 'text-properties) 'drawer 'outline))

It will pass in either 'drawer or 'outline, neither of which are valid given the alist they need to match against.

Still looking for how to customize org-fold-core--spec-symbols.

ckonstanski-olo commented 1 year ago

I contacted the org-mode mailing list and got a reply. https://lists.gnu.org/archive/html/emacs-orgmode/2023-05/msg00460.html

The answer I got was that the buffer is not being properly put into org-mode. So the bug does lie with the calling code, i.e. org-jira. Looking higher up the stack trace to get an idea of which buffer we are talking about and where we should add a call to org-mode.

Putting the buffer into org-mode would cause the function org-fold-initialize to be called, and org-fold-core--spec-symbols would gain entries for 'drawer and 'outline.

ckonstanski-olo commented 1 year ago

I got the org-jira buffer to automatically enter org-mode by adding '("\\.org\\'" . org-mode) to my auto-mode-alist.