"Fossies" - the Fresh Open Source Software Archive

Member "cli-1.1280.1/src/cli/commands/policy.ts" (20 Feb 2024, 697 Bytes) of package /linux/misc/snyk-cli-1.1280.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 import * as policy from 'snyk-policy';
    2 import { display } from '../../lib/display-policy';
    3 import {
    4   FailedToLoadPolicyError,
    5   PolicyNotFoundError,
    6   CustomError,
    7 } from '../../lib/errors';
    8 
    9 export default async function displayPolicy(path?: string): Promise<string> {
   10   try {
   11     const loadedPolicy = (await policy.load(path || process.cwd())) as Promise<
   12       string
   13     >;
   14     return await display(loadedPolicy);
   15   } catch (error) {
   16     let adaptedError: CustomError;
   17     if (error.code === 'ENOENT') {
   18       adaptedError = new PolicyNotFoundError();
   19     } else {
   20       adaptedError = new FailedToLoadPolicyError();
   21       adaptedError.innerError = error;
   22     }
   23     throw adaptedError;
   24   }
   25 }