shlogg · Early preview
Ramu Narasinga @karthik-m22

Improving Code Readability With Error Constants In Shadcn/ui

error.ts in shadcn/ui codebase contains 12 error variables as string numbers, used to improve readability. For example, MISSING_DIR_OR_EMPTY_PROJECT is used in preflight-init.ts to check for empty project.

In this article, we analyze how a file named error.ts is used across the shadcn/ui code base.


  
  
  utils/errors.ts

error.ts contains 12 variables:

export const MISSING_DIR_OR_EMPTY_PROJECT = "1"
export const EXISTING_CONFIG = "2"
export const MISSING_CONFIG = "3"
export const FAILED_CONFIG_READ = "4"
export const TAILWIND_NOT_CONFIGURED = "5"
export const IMPORT_ALIAS_MISSING = "6"
export const UNSUPPORTED_FRAMEWORK = "7"
export const COMPONENT_URL_NOT_FOUND = "8"
export const COMPONENT_URL_UNAUTHORIZED = "9"
export const COMPONENT_URL_FORBIDDEN = "10"
export const COMPONENT_URL_BAD_REQ...