Skip to content

Commit

Permalink
doc: document errors
Browse files Browse the repository at this point in the history
Add js-docs to document errors. Some functions throw the same type of error for different reasons. These should probably get different error types, or better represent their errors as part of their return-type. This is a first step to get an overview over the apps errors.
  • Loading branch information
ComradeVanti committed Dec 20, 2023
1 parent 2c0bdab commit 446bd21
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/cmd-add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ type AddResult = {
code: ResultCode;
};

/**
* @throws Error An unhandled error occurred
*/
export const add = async function (
pkgs: PackageReference | PackageReference[],
options: AddOptions
Expand Down
3 changes: 3 additions & 0 deletions src/cmd-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export type DepsOptions = CmdOptions<{
deep?: boolean;
}>;

/**
* @throws Error An unhandled error occurred
*/
export const deps = async function (
pkg: PackageReference,
options: DepsOptions
Expand Down
6 changes: 6 additions & 0 deletions src/cmd-login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export type LoginOptions = CmdOptions<{
alwaysAuth?: boolean;
}>;

/**
* @throws Error An unhandled error occurred
*/
export const login = async function (options: LoginOptions) {
// parse env
const env = await parseEnv(options, false);
Expand Down Expand Up @@ -114,6 +117,7 @@ const npmLogin = async function (

/**
* Write npm token to .npmrc
* @throws Error An unhandled error occurred
*/
const writeNpmToken = async function (registry: RegistryUrl, token: string) {
const configPath = getNpmrcPath();
Expand All @@ -131,6 +135,7 @@ const writeNpmToken = async function (registry: RegistryUrl, token: string) {

/**
* Return .npmrc config file path
* @throws Error Home-path could not be determined
*/
export const getNpmrcPath = function () {
const dirPath = process.env.USERPROFILE
Expand Down Expand Up @@ -179,6 +184,7 @@ export const generateNpmrcLines = function (

/**
* Write npm token to Unity
* @throws Error The specified authentication information was missing
*/
const writeUnityToken = async function (
configDir: string,
Expand Down
3 changes: 3 additions & 0 deletions src/registry-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ type NameVersionPair = {
version: SemanticVersion | "latest" | undefined;
};

/**
* @throws AssertionError The given parameter is not a {@link NpmClientError}
*/
export function assertIsNpmClientError(
x: unknown
): asserts x is NpmClientError {
Expand Down
1 change: 1 addition & 0 deletions src/types/editor-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export type EditorVersion = {
* Compares two editor versions for ordering
* @param a The first version
* @param b The second version
* @throws Error An editor version could not be parsed
*/
export const compareEditorVersion = function (
a: string,
Expand Down
1 change: 1 addition & 0 deletions src/types/registry-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function removeTrailingSlash(registry: RegistryUrl): RegistryUrl {
* - Prepending http if it is missing
* - Removing trailing slashes
* @param s The string
* @throws assert.AssertionError if string does not have valid format
*/
export function coerceRegistryUrl(s: string): RegistryUrl {
if (!s.toLowerCase().startsWith("http")) s = "http://" + s;
Expand Down
5 changes: 4 additions & 1 deletion src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ export type Env = {
editorVersion: string | null;
};

// Parse env
/**
* Parse env
* @throws Error An unhandled error occurred
*/
export const parseEnv = async function (
options: CmdOptions,
checkPath: boolean
Expand Down
3 changes: 3 additions & 0 deletions src/utils/error-type-guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { HttpErrorBase } from "npm-registry-fetch";
import { AssertionError } from "assert";
import ErrnoException = NodeJS.ErrnoException;

/**
* @throws AssertionError The given parameter is not an error
*/
export function assertIsError(x: unknown): asserts x is ErrnoException {
if (!(x instanceof Error))
throw new AssertionError({
Expand Down
1 change: 1 addition & 0 deletions src/utils/upm-config-io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const configFileName = ".upmconfig.toml";
* Gets the path to directory in which the upm config is stored
* @param wsl Whether WSL should be treated as Windows
* @param systemUser Whether to authenticate as a Windows system-user
* @throws Error Could not determine upm config directory
*/
export const getUpmConfigDir = async (
wsl: boolean,
Expand Down

0 comments on commit 446bd21

Please sign in to comment.