# gl-format-compiler-error

> Formats a webgl glsl compiler error.

Latest version **1.0.3** (published 2017-09-05) · Unlicense license · 0 weekly downloads

## Install

```sh
npm install gl-format-compiler-error
pnpm add gl-format-compiler-error
yarn add gl-format-compiler-error
bun add gl-format-compiler-error
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2017-09-05 |
| First published | 2015-11-24 |
| Weekly downloads | 0 |
| License | Unlicense |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Rye Terrell |
| Maintainers | wwwtyro |
| Keywords | stackgl, webgl, glsl |

## Links

- npm: https://www.npmjs.com/package/gl-format-compiler-error
- Repository: https://github.com/wwwtyro/gl-format-compiler-error
- Homepage: https://github.com/wwwtyro/gl-format-compiler-error#readme
- Issues: https://github.com/wwwtyro/gl-format-compiler-error/issues
- npm.io page: https://npm.io/package/gl-format-compiler-error

## Dependencies (4)

- [sprintf-js](https://npm.io/package/sprintf-js.md) ^1.0.3
- [gl-constants](https://npm.io/package/gl-constants.md) ^1.0.0
- [add-line-numbers](https://npm.io/package/add-line-numbers.md) ^1.0.1
- [glsl-shader-name](https://npm.io/package/glsl-shader-name.md) ^1.0.0

## Recent versions

- 1.0.3 (latest) — 2017-09-05
- 1.0.2 — 2015-11-24
- 1.0.1 — 2015-11-24
- 1.0.0 — 2015-11-24

## README

# gl-format-compiler-error

Formats a webgl glsl compiler error. Use in conjunction with
[glsl-shader-name](https://www.npmjs.com/package/glsl-shader-name) to include your shader's 
name in the formatted error string.

## Example

```js
    var formatCompilerError = require('gl-format-compiler-error');
    
    ...
    
    var shader = gl.createShader(type)
    gl.shaderSource(shader, src)
    gl.compileShader(shader)
    if(!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
        var errLog = gl.getShaderInfoLog(shader)
        var fmt = formatCompilerError(errLog, src, type);
        console.warn(fmt.long);
        throw new Error(fmt.short);
    }
```

yields warning:

```text
Error in vertex shader generic:
  13: 
  14: void main() {
  15:     bug;
^^^^: 'bug' : undeclared identifier

  17:     vUV = aUV;
  18:     vPos = vec3(uModel * vec4(aPosition, 1.0))
  19: }
^^^^: '}' : syntax error
```

and error:

```text
Uncaught Error: Error in vertex shader generic:
ERROR: 0:15: 'bug' : undeclared identifier 
ERROR: 0:19: '}' : syntax error 
```

## Usage

### Install

```sh
npm install gl-format-compiler-error --save
```

### API

```js
var formatCompilerError = require('gl-format-compiler-error');
```

#### `fmt = formatCompilerError(errLog, source, type)`

Takes `errLog` result from `gl.getShaderInfoLog`, the shader `source` string, and the `type` of shader,
either `gl.VERTEX_SHADER` or `gl.FRAGMENT_SHADER`. Returns an object that contains the long and short
form of the formatted error:

```js
{
    long: "long form error with code snippets",
    short: "short form error, similar to the original error log"
}
```

---
_Source: https://npm.io/package/gl-format-compiler-error · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
