From 151f6ea6767119039a9c4998e31571fec21cc538 Mon Sep 17 00:00:00 2001 From: TomokiMiyauci Date: Tue, 18 May 2021 21:34:09 +0900 Subject: [PATCH] :sparkles: Add error log output feature --- format/json.ts | 15 ++++++++------- mod.ts | 11 ++++++++++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/format/json.ts b/format/json.ts index a9a7de1..8e9d241 100644 --- a/format/json.ts +++ b/format/json.ts @@ -1,18 +1,19 @@ // Copyright 2021-present the Nameable authors. All rights reserved. MIT license. -import { entries, ifElse, isBoolean, length, N } from "../deps.ts"; +import { entries, ifElse, isBoolean, isString, length, NN } from "../deps.ts"; const json = (val: (readonly ["deno.land", boolean])[]) => val.reduce((acc, [registry, isAvailable]) => { return { ...acc, [registry]: isAvailable }; }, {} as Record<"deno.land", boolean>); -const summarize = (val: (readonly [string, boolean | Error])[]): { +const summarize = (val: (readonly [string, boolean | string])[]): { result: Record; hasError: boolean; - errors: [string, Error][]; + errors: [string, string][]; } => { - const errors = val.filter(([_, result]) => - N(isBoolean(result)) - ) as ([string, Error])[]; + const errors = val.filter(([_, result]) => isString(result)) as [ + string, + string, + ][]; const result = val.map(( [registry, result], @@ -23,7 +24,7 @@ const summarize = (val: (readonly [string, boolean | Error])[]): { return { result: json(result), - hasError: N(length(errors)), + hasError: NN(length(errors)), errors, }; }; diff --git a/mod.ts b/mod.ts index 9725e33..35f20a4 100644 --- a/mod.ts +++ b/mod.ts @@ -46,8 +46,17 @@ const checkName = async ( const resultAll = await Promise.all( (query as any[]).map((fn) => fn(name)), ); - const { result } = summarize(resultAll); + const { result, errors, hasError } = summarize(resultAll); + + logger("Results:"); + logger(outputFormat(json, result)); + if (hasError) { + console.log("\nErrors:"); + errors.forEach(([registry, message]) => { + logger(`${registry}: `, message); + }); + } }; const pickKeys = (map: Record, val: U[]): T[] =>