Skip to content

Commit e930d2c

Browse files
committed
Throw ConfigError to distinguish configuration errors
Useful to distinguish these more expected errors from other unexpected errors.
1 parent 7a6276e commit e930d2c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/sqlFormatter.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,27 @@ export const format = (query: string, cfg: Partial<FormatFnOptions> = {}): strin
7373
return new Formatter(options).format(query);
7474
};
7575

76+
export class ConfigError extends Error {}
77+
7678
function validateConfig(cfg: FormatFnOptions): FormatFnOptions {
7779
if (!supportedDialects.includes(cfg.language)) {
78-
throw new Error(`Unsupported SQL dialect: ${cfg.language}`);
80+
throw new ConfigError(`Unsupported SQL dialect: ${cfg.language}`);
7981
}
8082

8183
if (isNumber(cfg.multilineLists) && cfg.multilineLists <= 0) {
82-
throw new Error('multilineLists config must be a positive number.');
84+
throw new ConfigError('multilineLists config must be a positive number.');
8385
}
8486

8587
if (cfg.expressionWidth <= 0) {
86-
throw new Error(
88+
throw new ConfigError(
8789
`expressionWidth config must be positive number. Received ${cfg.expressionWidth} instead.`
8890
);
8991
}
9092

9193
if (cfg.commaPosition === 'before' && cfg.useTabs) {
92-
throw new Error('commaPosition: before does not work when tabs are used for indentation.');
94+
throw new ConfigError(
95+
'commaPosition: before does not work when tabs are used for indentation.'
96+
);
9397
}
9498

9599
return cfg;

0 commit comments

Comments
 (0)