Author Topic: Continue loading files in start-up file.  (Read 2704 times)

0 Members and 1 Guest are viewing this topic.

dubb

  • Swamp Rat
  • Posts: 1105
Continue loading files in start-up file.
« on: February 05, 2019, 02:52:11 PM »
In the startup file I load all of the lisp scripts one by one.
Code: [Select]
(load "abc")
(load "123")
(load "etc.....")
if one of those lisp files do not load, I wish to continue onto the next line of code or continue loading the next lisp file. Is this possible?

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Continue loading files in start-up file.
« Reply #1 on: February 05, 2019, 03:03:12 PM »
Code - Auto/Visual Lisp: [Select]
  1. (load "abc" nil)

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: Continue loading files in start-up file.
« Reply #2 on: February 05, 2019, 03:21:50 PM »
OR

Code - Auto/Visual Lisp: [Select]
  1. (load "123" "File load '123' failed ... ")
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

dubb

  • Swamp Rat
  • Posts: 1105
Re: Continue loading files in start-up file.
« Reply #3 on: February 05, 2019, 03:57:28 PM »
Thanks! I didn't know "LOAD" can take more than one argument.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Continue loading files in start-up file.
« Reply #4 on: February 05, 2019, 04:05:23 PM »
OR

Code - Auto/Visual Lisp: [Select]
  1. (load "123" "File load '123' failed ... ")

Unfortunately such messages would not be printed to the command-line unless the load expression were the last in the sequence of evaluation...

In the past I've considered using something like:
Code - Auto/Visual Lisp: [Select]
  1. (eval (load "123" '(princ "\n123 failed to load...")))
But this can cause issues if the AutoLISP file 123 returns an expression on loading that causes eval to either error or perform an undesired operation on load.

An alternative might be:
Code - Auto/Visual Lisp: [Select]
  1. (if (= 'some-obscure-symbol (load "abc" 'some-obscure-symbol))
  2.     (princ "\nabc failed to load.")
  3. )
With the symbol obscure enough to avoid the possibility of causing a false-negative since one could not determine the return value of the file to be loaded ahead of time.

dubb

  • Swamp Rat
  • Posts: 1105
Re: Continue loading files in start-up file.
« Reply #5 on: February 05, 2019, 04:26:57 PM »
Say if one of my scripts has a bug.
123.lsp contains a malformed list.
Code: [Select]
error: malformed list on input
Code: [Select]
(load "123" "Failed") will  break the start up file.
What could I do to continue loading the next script?


OR

Code - Auto/Visual Lisp: [Select]
  1. (load "123" "File load '123' failed ... ")

Unfortunately such messages would not be printed to the command-line unless the load expression were the last in the sequence of evaluation...

In the past I've considered using something like:
Code - Auto/Visual Lisp: [Select]
  1. (eval (load "123" '(princ "\n123 failed to load...")))
But this can cause issues if the AutoLISP file 123 returns an expression on loading that causes eval to either error or perform an undesired operation on load.

An alternative might be:
Code - Auto/Visual Lisp: [Select]
  1. (if (= 'some-obscure-symbol (load "abc" 'some-obscure-symbol))
  2.     (princ "\nabc failed to load.")
  3. )
With the symbol obscure enough to avoid the possibility of causing a false-negative since one could not determine the return value of the file to be loaded ahead of time.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Continue loading files in start-up file.
« Reply #6 on: February 05, 2019, 04:30:57 PM »
Sledgehammer approach:
Code - Auto/Visual Lisp: [Select]
  1. (vl-catch-all-apply 'load '("123"))

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Continue loading files in start-up file.
« Reply #7 on: February 05, 2019, 05:08:31 PM »
if one of my scripts has a bug.
123.lsp contains a malformed list.
Code: [Select]
error: malformed list on input
Code: [Select]
(load "123" "Failed") will  break the start up file.

What could I do to continue loading the next script?

Fix 123.lsp. :P

Kidding aside, note that you can catch (and report) error messages captured by vl-catch-all-apply whilst continuing on with execution (if that's desirable). Read up on vl-catch-all-apply, vl-catch-all-error-p and vl-catch-all-error-msg functions (failing latter spoon feeding).
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

dubb

  • Swamp Rat
  • Posts: 1105
Re: Continue loading files in start-up file.
« Reply #8 on: February 05, 2019, 07:30:13 PM »
You know what, you are right. I have to make sure the code is stable and ready to use. What happened was, I left for vacation and there was some code I worked on that had an extra parenthesis. Which prevented the startup file from executing every line.

if one of my scripts has a bug.
123.lsp contains a malformed list.
Code: [Select]
error: malformed list on input
Code: [Select]
(load "123" "Failed") will  break the start up file.

What could I do to continue loading the next script?

Fix 123.lsp. :P

Kidding aside, note that you can catch (and report) error messages captured by vl-catch-all-apply whilst continuing on with execution (if that's desirable). Read up on vl-catch-all-apply, vl-catch-all-error-p and vl-catch-all-error-msg functions (failing latter spoon feeding).