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

✨ Status type #193

Open
kosorin opened this issue Jun 14, 2024 · 1 comment
Open

✨ Status type #193

kosorin opened this issue Jun 14, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@kosorin
Copy link

kosorin commented Jun 14, 2024

One of the core feature is error handling (failed clause). It would be nice to have named status codes. I think of it as a C# enum. Basically they are just integer constants (Num without fractional part).

Example:

// 7za https://man.archlinux.org/man/7za.1.en#DIAGNOSTICS
status L7zaStatus { // Pascal case as other Amber types
  Success = 0,
  Warning = 1,
  Fatal = 2,
  BadCommandLineParameters = 7,
  NotEnoughMemory = 8,
  UserCancel = 255,
}

main {
    let archive = "path/to/archive.7z"
    $7za x {archive}$? failed {
        if {
            status == L7zaStatus.UserCancel {
                echo "user canceled "
            }
            // ... other exit codes...
            else {
                echo "unknown error {status}"
            }
        }
    }
}

They can be defined in library (pub + import):

// lib.ab
pub status Foo {
...
}

// app.ab
import { Foo } from "lib.ab"

EDIT:

Function could somehow specify its status type:

fun foo_bar(a: Num, b: Num) -> Num fail L7zaStatus {
   // ...
   fail L7zaStatus.Fatal
}

foo_bar(1, 2) failed {
  if status == L7zaStatus.Fatal { // <-- code completion in IDE provides list of L7zaStatus items
    // ...
  }
  if status == 42 {} // <-- it is ok to use Num
}
@arapower
Copy link
Collaborator

It may be possible to consider it if the Dictionary Data Type discussed here is implemented.

@Ph0enixKM Ph0enixKM changed the title Status type ✨ Status type Jun 17, 2024
@Mte90 Mte90 added the enhancement New feature or request label Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants