emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Kyle Meyer <kyle@kyleam.com>
To: Michael Powe <powem@ctpowe.net>
Cc: emacs-orgmode@gnu.org
Subject: [PATCH] org.el: Don't clear dynamic block if write function is undefined
Date: Thu, 04 Feb 2021 01:15:42 -0500	[thread overview]
Message-ID: <87wnvofje9.fsf@kyleam.com> (raw)
In-Reply-To: <CAF7nVLVRVrmCgMnMhga9+mtuE0nav-eH4C17Bf4EiEryowt27w@mail.gmail.com>

Michael Powe writes:

> Hello,
>
> After logging some clock time, I used the normal key combination, C-u C-c
> C-x C-u to update my timesheet tables, and received this error message.
>
> org-update-dblock: Symbol’s function definition is void:
> org-dblock-write:CLOCKTABLE
[...]
> Well, after recovering from my horror at losing my timesheets for a day's
> work, I was able to track down the problem: the function is case sensitive.
> At some point, (apparently) I fat-fingered a key combo & upcased the mode
> line for two tables. After returning them to l-case, all worked as it
> should.
>
> I dunno - should the function be case insensitive?

I don't think so.  Other libraries and users can define their own
dynamic blocks, and I don't think anything documents that the
org-dblock-write:<name> function must be all lower case.  However, I do
think we could improve the situation by signaling an error if the
function is unknown _before_ clearing the block.

With the below patch, you would have seen

  user-error: Unknown dynamic block type: CLOCKTABLE

and the existing block would have been left as is.  What do you think?

-- >8 --
Subject: [PATCH] org.el: Don't clear dynamic block if write function is
 undefined

* lisp/org.el (org-prepare-dblock): Check whether the block's write
function is defined before clearing the existing contents.
(org-map-dblocks): Relay the message of the caught error to help the
caller figure out what went wrong.

The write function may be undefined because the user unintentionally
modified the dynamic block name or didn't load a library, and deleting
contents in this situation can be alarming.  Instead signal an error
that's hopefully enough for the user to figure out what went wrong.

Reported-by: Michael Powe <powem@ctpowe.net>
Ref: CAF7nVLVRVrmCgMnMhga9+mtuE0nav-eH4C17Bf4EiEryowt27w@mail.gmail.com
---
 lisp/org.el | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 5b1443c4e..c9f58c9a5 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -9165,6 +9165,8 @@ (defun org-prepare-dblock ()
 	 (name (org-no-properties (match-string 1)))
 	 (params (append (list :name name)
 			 (read (concat "(" (match-string 3) ")")))))
+    (unless (fboundp (intern (concat "org-dblock-write:" name)))
+      (user-error "Unknown dynamic block type: %s" name))
     (save-excursion
       (beginning-of-line 1)
       (skip-chars-forward " \t")
@@ -9189,9 +9191,11 @@ (defun org-map-dblocks (&optional command)
       (while (re-search-forward org-dblock-start-re nil t)
 	(goto-char (match-beginning 0))
         (save-excursion
-          (condition-case nil
+          (condition-case err
               (funcall cmd)
-            (error (message "Error during update of dynamic block"))))
+            (error
+             (message "Error during update of dynamic block: %s"
+                      (error-message-string err)))))
 	(unless (re-search-forward org-dblock-end-re nil t)
 	  (error "Dynamic block not terminated"))))))
 

base-commit: 369eb2739787b9b24399c803be31e4e793113dd1
-- 
2.30.0




      reply	other threads:[~2021-02-04  6:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-16  1:13 Error with org-update-dblock Michael Powe
2021-02-04  6:15 ` Kyle Meyer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wnvofje9.fsf@kyleam.com \
    --to=kyle@kyleam.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=powem@ctpowe.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).