Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,54 @@ const configuration = getConfiguration();
} as const;
```

### Error Handling

Throw an error when a function cannot complete its job, and handle it where the caller can respond. Do not return a sentinel string or flag that every caller must remember to check.

```typescript
// ❌ BAD — every caller has to check the returned string
function foo(): 'good' | 'bad' {
if (somethingNotRight) {
return 'bad';
}

doTheRightThing();
return 'good';
}

function bar(): void {
const result = foo();

if (result === 'bad') {
console.error('bad message for logging');
interaction.reply('bad message to user');
}

if (result === 'good') {
interaction.reply('good message to user');
}
}

// ✅ GOOD — the failure is thrown and handled in one place
function foo(): void {
if (somethingNotRight) {
throw new Error('something is not right');
}

doTheRightThing();
}

function bar(): void {
try {
foo();
interaction.reply('success, expected outcome');
} catch (error) {
console.error(error);
interaction.reply(error.message);
}
}
```

## Configuration Is the Source of Truth

Root-level config files define how this project is built, linted, formatted, and run. **Do not invent parallel config** (no new ESLint/Prettier/Biome/Jest/Vitest configs, no duplicate tsconfig variants, no ad-hoc tooling files).
Expand Down
Loading