From 4731f4800c1bd62cb77112ef8c9f553ae9164395 Mon Sep 17 00:00:00 2001 From: uki00a Date: Mon, 13 Jul 2020 21:00:56 +0900 Subject: fix(Deno.ppid): improve error message when --unstable is missing (#6717) --- cli/js/diagnostics_util.ts | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) (limited to 'cli/js') diff --git a/cli/js/diagnostics_util.ts b/cli/js/diagnostics_util.ts index 905a4397c..3e0bfde27 100644 --- a/cli/js/diagnostics_util.ts +++ b/cli/js/diagnostics_util.ts @@ -64,20 +64,43 @@ const unstableDenoGlobalProperties = [ "Permissions", "PermissionStatus", "hostname", + "ppid", ]; function transformMessageText(messageText: string, code: number): string { - if (code === 2339) { - const property = messageText - .replace(/^Property '/, "") - .replace(/' does not exist on type 'typeof Deno'\.$/, ""); - if ( - messageText.endsWith("on type 'typeof Deno'.") && - unstableDenoGlobalProperties.includes(property) - ) { - return `${messageText} 'Deno.${property}' is an unstable API. Did you forget to run with the '--unstable' flag?`; + switch (code) { + case 2339: { + const property = messageText + .replace(/^Property '/, "") + .replace(/' does not exist on type 'typeof Deno'\./, ""); + + if ( + messageText.endsWith("on type 'typeof Deno'.") && + unstableDenoGlobalProperties.includes(property) + ) { + return `${messageText} 'Deno.${property}' is an unstable API. Did you forget to run with the '--unstable' flag?`; + } + break; + } + case 2551: { + const suggestionMessagePattern = / Did you mean '(.+)'\?$/; + const property = messageText + .replace(/^Property '/, "") + .replace(/' does not exist on type 'typeof Deno'\./, "") + .replace(suggestionMessagePattern, ""); + const suggestion = messageText.match(suggestionMessagePattern); + const replacedMessageText = messageText.replace( + suggestionMessagePattern, + "" + ); + if (suggestion && unstableDenoGlobalProperties.includes(property)) { + const suggestedProperty = suggestion[1]; + return `${replacedMessageText} 'Deno.${property}' is an unstable API. Did you forget to run with the '--unstable' flag, or did you mean '${suggestedProperty}'?`; + } + break; } } + return messageText; } -- cgit v1.2.3