diff --git a/autoload/dpp/util.vim b/autoload/dpp/util.vim index a3d91f1..21dbeee 100644 --- a/autoload/dpp/util.vim +++ b/autoload/dpp/util.vim @@ -1,9 +1,11 @@ const s:is_windows = has('win32') || has('win64') function dpp#util#_error(msg) abort - for mes in a:msg->s:msg2list() - echohl WarningMsg | echomsg '[dpp] ' .. mes | echohl None + echohl Error + for line in a:string->string()->split("\n") + echomsg printf('[%s] %s', a:name, line) endfor + echohl None endfunction function dpp#util#_get_plugins(plugins) abort @@ -132,9 +134,6 @@ function dpp#util#_tsort(plugins) abort return sorted endfunction -function s:msg2list(expr) abort - return a:expr->type() ==# v:t_list ? a:expr : a:expr->split('\n') -endfunction function s:tsort_impl(target, mark, sorted) abort if a:target->empty() || a:mark->has_key(a:target.name) diff --git a/denops/dpp/context.ts b/denops/dpp/context.ts index 2a7efc6..7b1df25 100644 --- a/denops/dpp/context.ts +++ b/denops/dpp/context.ts @@ -7,6 +7,7 @@ import { ExtOptions, ProtocolOptions, } from "./types.ts"; +import { printError } from "./utils.ts"; // where // T: Object @@ -194,8 +195,8 @@ export class ContextBuilder { ) { for (const key in options) { if (!(key in defaults)) { - await denops.call( - "dpp#util#_error", + await printError( + denops, `Invalid ${name}: "${key}"`, ); } diff --git a/denops/dpp/dpp.ts b/denops/dpp/dpp.ts index 5780371..b7fbed4 100644 --- a/denops/dpp/dpp.ts +++ b/denops/dpp/dpp.ts @@ -22,10 +22,10 @@ import { ConfigReturn } from "./base/config.ts"; import { extAction, getProtocols } from "./ext.ts"; import { convert2List, - errorException, isDirectory, linkPath, parseHooksFile, + printError, } from "./utils.ts"; export class Dpp { @@ -186,8 +186,8 @@ export class Dpp { for (const depend of depends) { const plugin = recordPlugins[depend]; if (!plugin) { - await denops.call( - "dpp#util#_error", + await printError( + denops, `Not found dependency: "${depend}"`, ); continue; @@ -405,7 +405,7 @@ export class Dpp { try { await denops.cmd(`silent helptags ${docDir}`); } catch (e: unknown) { - await errorException( + await printError( denops, e, `:helptags failed`, diff --git a/denops/dpp/ext.ts b/denops/dpp/ext.ts index dea1ffb..709b202 100644 --- a/denops/dpp/ext.ts +++ b/denops/dpp/ext.ts @@ -24,7 +24,7 @@ import { import { Loader } from "./loader.ts"; import { defaultExtOptions } from "./base/ext.ts"; import { defaultProtocolOptions } from "./base/protocol.ts"; -import { errorException } from "./utils.ts"; +import { printError } from "./utils.ts"; export async function getProtocols( denops: Denops, @@ -75,8 +75,8 @@ export async function extAction( const action = ext.actions[actionName]; if (!action) { - await denops.call( - "dpp#util#_error", + await printError( + denops, `Not found UI action: ${actionName}`, ); return; @@ -125,8 +125,8 @@ async function getExt( const ext = loader.getExt(name); if (!ext) { if (name.length !== 0) { - await denops.call( - "dpp#util#_error", + await printError( + denops, `Not found ext: "${name}"`, ); } @@ -162,8 +162,8 @@ async function getProtocol( const protocol = loader.getProtocol(name); if (!protocol) { if (name.length !== 0) { - await denops.call( - "dpp#util#_error", + await printError( + denops, `Not found protocol: "${name}"`, ); } @@ -204,7 +204,7 @@ async function checkExtOnInit( ext.isInitialized = true; } catch (e: unknown) { - await errorException( + await printError( denops, e, `ext: ${ext.name} "onInit()" failed`, @@ -253,7 +253,7 @@ async function checkProtocolOnInit( protocol.isInitialized = true; } catch (e: unknown) { - await errorException( + await printError( denops, e, `protocol: ${protocol.name} "onInit()" failed`, diff --git a/denops/dpp/utils.ts b/denops/dpp/utils.ts index 874f16f..f48ca7d 100644 --- a/denops/dpp/utils.ts +++ b/denops/dpp/utils.ts @@ -1,33 +1,21 @@ import { assertEquals, Denops, is, join } from "./deps.ts"; import { Plugin } from "./types.ts"; -export async function errorException( +export async function printError( denops: Denops, - e: unknown, - message: string, + ...messages: unknown[] ) { - await denops.call( - "dpp#util#_error", - message, - ); - if (e instanceof Error) { - await denops.call( - "dpp#util#_error", - e.message, - ); - if (e.stack) { - await denops.call( - "dpp#util#_error", - e.stack, - ); + const message = messages.map((v) => { + if (v instanceof Error) { + // NOTE: In Deno, Prefer `Error.stack` because it contains `Error.message`. + return `${v.stack ?? v}`; + } else if (typeof v === "object") { + return JSON.stringify(v); + } else { + return `${v}`; } - } else { - await denops.call( - "dpp#util#_error", - "unknown error object", - ); - console.error(e); - } + }).join("\n"); + await denops.call("dpp#util#_error", message); } export function convert2List(expr: T | T[] | undefined): T[] {