or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

application.mdcommands-and-routing.mdconfiguration-and-context.mddocumentation-and-help.mderror-handling.mdexit-codes.mdflag-parameters.mdindex.mdparameter-parsers.mdpositional-parameters.mdtext-and-localization.md

exit-codes.mddocs/

0

# Exit Codes

1

2

Exit code constants for process control.

3

4

## ExitCode Constants

5

6

```typescript { .api }

7

const ExitCode = {

8

Success: 0, // Command executed successfully

9

CommandRunError: 1, // Command threw error

10

InternalError: -1, // Framework internal error

11

CommandLoadError: -2, // Failed to load command module

12

ContextLoadError: -3, // Failed to load command context

13

InvalidArgument: -4, // Invalid arguments provided

14

UnknownCommand: -5 // Command not found

15

}

16

```

17

18

## Exit Code Usage

19

20

```typescript

21

await run(app, process.argv.slice(2), { process });

22

23

// Check exit code

24

if (process.exitCode === ExitCode.Success) {

25

console.log("✓ Success");

26

} else if (process.exitCode === ExitCode.InvalidArgument) {

27

console.error("✗ Invalid arguments");

28

} else if (process.exitCode === ExitCode.UnknownCommand) {

29

console.error("✗ Command not found");

30

}

31

```

32

33

## Custom Exit Codes

34

35

```typescript

36

class BusinessError extends Error {

37

constructor(message: string, public exitCode: number) {

38

super(message);

39

}

40

}

41

42

const app = buildApplication(command, {

43

name: "myapp",

44

determineExitCode: (exc) => {

45

if (exc instanceof BusinessError) return exc.exitCode;

46

if (exc instanceof Error && exc.message.includes("timeout")) return 124;

47

return ExitCode.CommandRunError;

48

}

49

});

50

51

// Command that uses custom exit codes

52

const command = buildCommand({

53

func: async function() {

54

throw new BusinessError("Payment failed", 10);

55

},

56

parameters: {},

57

docs: { brief: "Process payment" }

58

});

59

60

await run(app, [], { process });

61

// process.exitCode will be 10

62

```

63

64

## Exit Code Scenarios

65

66

| Code | Scenario | Example |

67

|------|----------|---------|

68

| 0 | Success | Command completes without error |

69

| 1 | Command error | Command throws or returns Error |

70

| -1 | Internal error | Framework bug (rare) |

71

| -2 | Load error | `loader: () => import("./nonexistent.js")` |

72

| -3 | Context error | `forCommand` throws |

73

| -4 | Invalid args | `--port abc` when expecting number |

74

| -5 | Unknown command | `myapp unknown-cmd` |

75

76

## Environment Variables

77

78

```typescript

79

// Skip version check

80

STRICLI_SKIP_VERSION_CHECK=1 myapp command

81

82

// Disable colors

83

STRICLI_NO_COLOR=1 myapp --help

84

85

// Both

86

STRICLI_SKIP_VERSION_CHECK=1 STRICLI_NO_COLOR=1 myapp command

87

```

88

89

**Variables:**

90

- `STRICLI_SKIP_VERSION_CHECK=1`: Skip automatic version checking

91

- `STRICLI_NO_COLOR=1`: Disable ANSI color output

92

93

## CI/CD Integration

94

95

```typescript

96

// Disable colors and version checks in CI

97

const isCI = process.env.CI === "true";

98

if (isCI) {

99

process.env.STRICLI_SKIP_VERSION_CHECK = "1";

100

process.env.STRICLI_NO_COLOR = "1";

101

}

102

103

await run(app, process.argv.slice(2), { process });

104

process.exit(process.exitCode || 0);

105

```

106

107

## Related

108

109

- [Error Handling](./error-handling.md)

110

- [Configuration and Context](./configuration-and-context.md)

111