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

Improve error checking and logic #58

Merged
merged 2 commits into from
Aug 8, 2024

Conversation

friendly-bits
Copy link
Collaborator

@friendly-bits friendly-bits commented Aug 5, 2024

(Updated)

  • Implement much more error checking
  • Implement hierarchical error propagation
  • Move commands initialization code to init_command() and call that function from all main command functions
  • Call abl_luci_exit() before exiting (if it's defined by external sourcing script)
  • Kill luci.adblock-lean when stopping or restarting
  • Get rid of some of the nested logic
  • Collect errors in ${failure_msg} and ${luci_errors} and call reg_failure() once before exiting

@friendly-bits friendly-bits force-pushed the improve_error_checking branch from 6636808 to dda43db Compare August 5, 2024 15:22
@friendly-bits
Copy link
Collaborator Author

^ Fixed sucess, and Ok, Ok? :)

@friendly-bits friendly-bits force-pushed the improve_error_checking branch from dda43db to 1c2fa17 Compare August 5, 2024 18:54
@friendly-bits
Copy link
Collaborator Author

^

  • manually call status() on 'status' command; call cleanup_and_exit() after status() returns; if sourced then return the correct return code to the sourcing script
    (I know that status doesn't need any cleanup but it was more convenient and shorter to call an already existing function, and that function doesn't delete things when not needed)
  • log_failure(): register most recent error in luci_error variable

@friendly-bits friendly-bits force-pushed the improve_error_checking branch from 1c2fa17 to f2f656d Compare August 6, 2024 13:02
@friendly-bits
Copy link
Collaborator Author

^

  • call exit rather than return in the code of the main commands

  • cleanup_and_exit(): always exit rather than returning

  • trap: always exit rather than returning

  • move commands initialization code to init_command()

  • main command functions: call init_command()

  • init_command(): set traps unconditionally

  • cleanup_and_exit(): rely on abl_luci_exit() function being defined in sourcing script, rather than on ${abl_sourced} var

  • cleanup_and_exit(): call abl_luci_exit() before exit (if defined)

  • stop(): accept exit code for argument

  • kill_abl_pids(): also kill luci.adblock-lean if it's running

  • change var name 'luci_error' -> 'luci_errors'

  • log_failure(): collect errors in ${failure_msg} and ${luci_errors} rather than executing report_failure for every error

@friendly-bits friendly-bits force-pushed the improve_error_checking branch from f2f656d to 2970f18 Compare August 6, 2024 16:33
@friendly-bits
Copy link
Collaborator Author

friendly-bits commented Aug 6, 2024

^

  • cleanup_and_exit(): check if failure message is set before executing ${report_failure}
  • gen_stats(): support the '-noexit' argument to return to the calling function
  • status(): call gen_stats() with the '-noexit' argument
  • rename log_failure() to reg_failure()

@friendly-bits friendly-bits force-pushed the improve_error_checking branch from 2970f18 to 6d62028 Compare August 7, 2024 09:37
@friendly-bits
Copy link
Collaborator Author

^

  • bytes2human(): fix the comment
  • stop(): support optional '-noexit' argument, return to caller when specified
  • restart(): implement function (otherwise restart wouldn't work)
  • reload(): implement function stub - simply calls restart()
  • update_pid_action(): accept rc=3 from check_lock(), reject rc=2
  • check_lock(): check if current PID owns the lock file, and if so then return code 3

The above is mainly to fix boot, restart and reload commands

@friendly-bits friendly-bits force-pushed the improve_error_checking branch from 6d62028 to 9bc6280 Compare August 8, 2024 08:57
@friendly-bits
Copy link
Collaborator Author

^ Regardless of ${download_failed_action} value, always skip file part larger than ${max_blocklist_file_part_size_KB}.

@friendly-bits friendly-bits force-pushed the improve_error_checking branch from 9bc6280 to 7fe8a7d Compare August 8, 2024 12:07
@friendly-bits
Copy link
Collaborator Author

^ init_command(): if failed to create/acquire lock, unset ${lock_req}, ${cleanup_req} before exit
(turns out there was a bug where running the start command while another command was running would remove the lock and do cleanup, which should not happen)

@friendly-bits
Copy link
Collaborator Author

^ Functions reordering commit

@lynxthecat
Copy link
Owner

lynxthecat commented Aug 8, 2024

I think safe to merge this in now? Or shall I hold fire for a bit longer?

@friendly-bits
Copy link
Collaborator Author

Yes, I think it's safe to merge.

@lynxthecat lynxthecat merged commit a72e93d into lynxthecat:master Aug 8, 2024
@friendly-bits friendly-bits deleted the improve_error_checking branch August 8, 2024 20:34
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

Successfully merging this pull request may close these issues.

2 participants