-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: avoid throwing exceptions, better error messages
- Loading branch information
Showing
3 changed files
with
101 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
export const CLI_NAME = 'ztd' | ||
|
||
export const DEBUG_PREFIX = 'ztd' | ||
|
||
export const ERROR_PREFIX = '❌' | ||
|
||
export const INFO_PREFIX = '🛈' | ||
|
||
export const LINK_ISSUE_BUG = `https://github.com/jackdbd/zod-to-doc/labels/bug` | ||
|
||
export const LINK_ISSUE_ENHANCEMENT = `https://github.com/jackdbd/zod-to-doc/labels/enhancement` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { ERROR_PREFIX, LINK_ISSUE_BUG } from './constants.js' | ||
|
||
// Call To Action to encourage users to submit a bug report in case of an error | ||
const CTA_BUG = `Do you think this is a bug? Please submit an issue here: ${LINK_ISSUE_BUG}` | ||
|
||
export const esModuleNotFound = (filepath: string) => { | ||
const summary = `${ERROR_PREFIX} ES module not found` | ||
const details = [ | ||
`Not found: ${filepath}`, | ||
`TIP: Try double-checking the file path.`, | ||
CTA_BUG | ||
] | ||
return [summary, ...details].join('\n\n') | ||
} | ||
|
||
export const couldNotGenerateTable = (error: Error) => { | ||
const summary = `${ERROR_PREFIX} Could not generate table from Zod schema` | ||
const details = [ | ||
`Error: ${error.message}`, | ||
`TIP: Try double-checking your Zod schema.`, | ||
CTA_BUG | ||
] | ||
return [summary, ...details].join('\n\n') | ||
} | ||
|
||
export const documentNotFound = (filepath: string) => { | ||
const summary = `${ERROR_PREFIX} Document not found` | ||
const details = [ | ||
`Not found: ${filepath}`, | ||
`TIP: Try double-checking the file path.`, | ||
CTA_BUG | ||
] | ||
return [summary, ...details].join('\n\n') | ||
} | ||
|
||
export const schemaNotFound = (name: string, filepath: string) => { | ||
const summary = `${ERROR_PREFIX} Zod schema not found` | ||
const details = [ | ||
`Not found: ${name}`, | ||
`TIP: Try double-checking the name of the Zod schema you want to import from ${filepath}.`, | ||
CTA_BUG | ||
] | ||
return [summary, ...details].join('\n\n') | ||
} | ||
|
||
export const placeholderNotFound = (placeholder: string, filepath: string) => { | ||
const summary = `${ERROR_PREFIX} Placeholder not found` | ||
const placeholder_begin = `<!-- BEGIN ${placeholder} -->` | ||
const placeholder_end = `<!-- END ${placeholder} -->` | ||
const details = [ | ||
`Not found: ${placeholder}`, | ||
`TIP: Please make sure to put both ${placeholder_begin} and ${placeholder_end} in ${filepath}`, | ||
CTA_BUG | ||
] | ||
return [summary, ...details].join('\n\n') | ||
} |