condy0919 / spdx.el

Insert SPDX license header
GNU General Public License v3.0
13 stars 4 forks source link

Wrong type argument error in empty LICENSE file #4

Closed galeo closed 3 years ago

galeo commented 3 years ago

Thanks for this convenient package. When try to call spdx-insert-spdx in an empty LICENSE file, it would lead to wrong-type-argument error. Here is the backtrace log:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  string-match("[ \11]*\\'" nil)
  comment-add(nil)
  spdx-comment-start()
  eval((spdx-comment-start))
  tempo-insert((spdx-comment-start) nil)
  #f(compiled-function (elt) #<bytecode 0x1ffe90c31235>)((spdx-comment-start))
  mapc(#f(compiled-function (elt) #<bytecode 0x1ffe90c31235>) ((spdx-comment-start) (spdx-license-format) (spdx-comment-end) > n>))
  tempo-insert-template(tempo-template-spdx nil)
  tempo-template-spdx()
  spdx-insert-spdx()
  funcall-interactively(spdx-insert-spdx)
  call-interactively(spdx-insert-spdx record nil)
  command-execute(spdx-insert-spdx record)
  ...
condy0919 commented 3 years ago

An empty LICENSE file has no comment syntax, so it's expected. It's mainly used in those modes derived from prog-mode

galeo commented 3 years ago

Should this error be handled? Or prompt that it is unavailable in current mode?

condy0919 commented 3 years ago

Yes, thanks for advice.

It should be fixed in 20e48f3b439ff2bfd24b6f68bcb8bf802b1f40e3

galeo commented 3 years ago

Thanks.

mattiasb commented 3 years ago

I stumbled over this as well, found this issue, upgraded and now I get an actionable explanation. That's great!

However, if I call comment-or-uncomment-region (which also needs comment-start to be set) I get an option to set the comment syntax.

Maybe a call to (comment-normalize-vars) instead of the (spdx--ensure-comment-syntax-defined) defun would be even better? :)

condy0919 commented 3 years ago

Good tips