From 6a5158df94d6a0c6e72ae4cb41a0ae032673807b Mon Sep 17 00:00:00 2001 From: Karsten Schmidt Date: Fri, 24 Sep 2021 12:03:06 +0200 Subject: [PATCH] refactor(webgl): redefine WebGL error, migrate logger --- packages/webgl/src/error.ts | 10 ++++------ packages/webgl/src/index.ts | 2 +- packages/webgl/src/{api => }/logger.ts | 0 packages/webgl/src/shader.ts | 11 ++++++++--- 4 files changed, 13 insertions(+), 10 deletions(-) rename packages/webgl/src/{api => }/logger.ts (100%) diff --git a/packages/webgl/src/error.ts b/packages/webgl/src/error.ts index 4df70f8b6e..937f7e49da 100644 --- a/packages/webgl/src/error.ts +++ b/packages/webgl/src/error.ts @@ -1,9 +1,7 @@ -export class WebGLError extends Error { - constructor(msg?: string) { - super(`WebGL error ${msg ? ": " + msg : ""}`); - } -} +import { defError } from "@thi.ng/errors"; -export const error = (msg?: string) => { +export const WebGLError = defError(() => "WebGL"); + +export const error = (msg?: string): never => { throw new WebGLError(msg); }; diff --git a/packages/webgl/src/index.ts b/packages/webgl/src/index.ts index 5745999a2d..198d234ac2 100644 --- a/packages/webgl/src/index.ts +++ b/packages/webgl/src/index.ts @@ -3,7 +3,6 @@ export * from "./api/buffers"; export * from "./api/canvas"; export * from "./api/ext"; export * from "./api/glsl"; -export * from "./api/logger"; export * from "./api/material"; export * from "./api/model"; export * from "./api/shader"; @@ -15,6 +14,7 @@ export * from "./checks"; export * from "./draw"; export * from "./error"; export * from "./fbo"; +export * from "./logger"; export * from "./material"; export * from "./matrices"; export * from "./multipass"; diff --git a/packages/webgl/src/api/logger.ts b/packages/webgl/src/logger.ts similarity index 100% rename from packages/webgl/src/api/logger.ts rename to packages/webgl/src/logger.ts diff --git a/packages/webgl/src/shader.ts b/packages/webgl/src/shader.ts index 3e9bf2de93..b108f4a296 100644 --- a/packages/webgl/src/shader.ts +++ b/packages/webgl/src/shader.ts @@ -20,7 +20,6 @@ import { GL_EXT_INFO, } from "./api/ext"; import type { GLSL } from "./api/glsl"; -import { LOGGER } from "./api/logger"; import type { ModelAttributeSpecs, ModelSpec } from "./api/model"; import { DEFAULT_OUTPUT, @@ -44,6 +43,7 @@ import { import { getExtensions } from "./canvas"; import { isGL2Context } from "./checks"; import { error } from "./error"; +import { LOGGER } from "./logger"; import { GLSL_HEADER, NO_PREFIXES, SYNTAX } from "./syntax"; import { UNIFORM_SETTERS } from "./uniforms"; @@ -57,10 +57,15 @@ export class Shader implements IShader { state: Partial; protected warnAttrib = doOnce((id: string) => - LOGGER.warn(`unknown attrib: ${id}`) + LOGGER.warn( + `unknown attrib: ${id} (no further warnings will be shown...)` + ) ); + protected warnUni = doOnce((id: string) => - LOGGER.warn(`unknown uniform: ${id}`) + LOGGER.warn( + `unknown uniform: ${id} (no further warnings will be shown...)` + ) ); constructor(