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

Add api exception mode #1

Open
mfs12 opened this issue Jun 3, 2021 · 2 comments
Open

Add api exception mode #1

mfs12 opened this issue Jun 3, 2021 · 2 comments

Comments

@mfs12
Copy link
Collaborator

mfs12 commented Jun 3, 2021

To improve programming experience the error handling should use native language features. In python this are exceptions.

Clarification is needed here for go language as well.

As many errors can be thrown and should shown as easy and clear as possible to the programmer/user most errors should be mapped to exceptions. Here is more specification needed.

@mfs12
Copy link
Collaborator Author

mfs12 commented Jun 3, 2021

This is how a solution could look like for python:

class DsfException(Exception):
    """Base class for all DSF exceptions"""
    def __init__(self, message):
        super().__init__(message)


class InternalServerException(DsfException):
    """Exception returned by the server for an arbitrary problem"""

    def __init__(self):
        super().__init__("Internal Server Exception")


class ErrorResponseException(DsfException):
    """Exception returned if an Error Response is received"""

    def __init__(self, error_type: str, error_message: str):
        super().__init__("{}: {}".format(error_type, error_message))

This is an incomplete overview of found errors

  • NotImplementedError Error: M3: Command is not supported in machine mode FFF
  • NotImplementedError Error: Operation is not supported
  • NotImplementedError Error: M260: I2C not available
  • MissingParameter Error: M42: missing parameter 'P' or Error: M118: missing parameter 'S' or Error: M307: missing parameter 'H' or Error: M581: missing parameter 'T' or Error: M591: missing parameter 'D'
  • OutOfRangeError Error: M593: parameter 'F' too low
  • DeprecationWarning Error: M305: M305 has been replaced by M308 and M950 in RepRapFirmware 3
  • FileNotFoundError Error: M24: Cannot print, because no file is selected!
  • AlreadyStopped Error: M25: Cannot pause print, because no file is being printed!
  • SHA1Error Error: M38: Could not compute SHA1 checksum for file F a l s e: Could not find file '/F a l s e'.
  • FileNotFound Error: M375: Failed to load height map from file heightmap.csv: Could not find file '/opt/dsf/sd/sys/heightmap.csv'.
  • DirectoryNotFound Error: M470: Missing directory name
  • RenamingError Error: M471: Failed to rename file or directory to : Value cannot be null. (Parameter 'input')
  • NetworkError Error: M540: Network-related commands are not supported when using an attached Single Board Computer
  • InvalidStateError Error: M585: a axis has not been homed

@wilriker
Copy link
Contributor

wilriker commented Jun 4, 2021

Clarification is needed here for go language as well.
Go uses instances of struct error for error handling. You can either return an generic error message by creating it via ```
errors.New("error message")

or create pseudo-static instances like

var ErrSomeDecriptiveName = errors.New("error message")

and then the user can compare against this instance.

AFAIR the Go impl already returns errors where appropriate.

@mfs12 mfs12 transferred this issue from Duet3D/DSF-APIs Jun 4, 2021
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

No branches or pull requests

2 participants