{"id":15387294,"url":"https://github.com/rhysd/locerr","last_synced_at":"2026-03-01T19:32:12.497Z","repository":{"id":57503522,"uuid":"93145755","full_name":"rhysd/locerr","owner":"rhysd","description":":x: locerr (locational error): Library for nice-looking errors in source code","archived":false,"fork":false,"pushed_at":"2017-07-10T12:08:03.000Z","size":43,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-11T02:52:47.345Z","etag":null,"topics":["error","go","golang","source"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rhysd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-02T08:39:53.000Z","updated_at":"2025-03-24T09:48:08.000Z","dependencies_parsed_at":"2022-09-13T08:23:15.424Z","dependency_job_id":null,"html_url":"https://github.com/rhysd/locerr","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rhysd/locerr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Flocerr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Flocerr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Flocerr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Flocerr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rhysd","download_url":"https://codeload.github.com/rhysd/locerr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Flocerr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29981413,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T16:35:47.903Z","status":"ssl_error","status_checked_at":"2026-03-01T16:35:44.899Z","response_time":124,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["error","go","golang","source"],"created_at":"2024-10-01T14:53:32.421Z","updated_at":"2026-03-01T19:32:12.476Z","avatar_url":"https://github.com/rhysd.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":":x: locerr\n==========\n[![Build Status][build badge]][travis result]\n[![Windows Build status][windows build badge]][appveyor result]\n[![Coverage Status][coverage status]][coverage result]\n[![GoDoc][godoc badge]][locerr document]\n\n[locerr][locerr document] is a small library to make a nice-looking locational error in a source code.\nIt provides a struct to represent a source file, a specific position in code and an error related to\nspecific range or position in source.\n\nThis library is useful to provide a unified look for error messages raised by compilers, interpreters\nor translators.\n\nBy using `locerr.Source` and `locerr.Pos` types as position information, this library can provide\nan error type which shows nice look error message.\n\n- It shows the code snippet which caused an error\n- Enable to add notes to error by nesting an error instance like [pkg/errors](https://github.com/pkg/errors)\n- Proper location is automatically added to error messages and notes\n- Colorized label like 'Error:' or 'Note:'\n- Windows is supported\n\nIt's important to make a good error when compilation or execution errors found. [locerr][locerr document]\nhelps it. This library is actually used in some my compiler implementation.\n\n## Installation\n\nPlease use `go get`.\n\n```console\n$ go get -u github.com/rhysd/locerr\n```\n\n## Usage\n\nAs example, let's say to make a locational error for following pseudo code. In this code, function\n`foo` is defined with 1 parameter but called with 3 parameters.\n\n```\nfunction foo(x: bool): int {\n  return (if x then 42 else 21)\n}\n\nfunction main() {\n  foo(true,\n      42,\n      \"test\")\n}\n```\n\nWe can make a locational error with some notes using locerr as following.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/rhysd/locerr\"\n)\n\nfunc main() {\n\t// At first you should gain entire source as *locerr.Source instance.\n\n\tcode :=\n`function foo(x: bool): int {\n  return (if x then 42 else 21)\n}\n\nfunction main() {\n  foo(true,\n      42,\n      \"test\")\n}`\n\tsrc := locerr.NewDummySource(code)\n\n\t// You can get *locerr.Source instance from file (NewSourceFromFile) or stdin (NewSourceFromStdin) also.\n\n\t// Let's say to find an error at some range in the source. 'start' indicates the head of the first argument.\n    // 'end' indicates the end of the last argument.\n\n\tstart := locerr.Pos{\n\t\tOffset: 88,\n\t\tLine:   6,\n\t\tColumn: 7,\n\t\tFile:   src,\n\t}\n\tend := locerr.Pos{\n\t\tOffset: 116,\n\t\tLine:   9,\n\t\tColumn: 12,\n\t\tFile:   src,\n\t}\n\n\t// NewError or other factory functions make a new error instance with the range. locerr.Error instance\n\t// implements error interface so it can be handled like other error types.\n\n\terr := locerr.ErrorIn(start, end, \"Calling 'foo' with wrong number of argument\")\n\n\t// Assume that you find additional information (location of variable and its type). Then you can add some\n\t// notes to the error. Notes can be added by wrapping errors like pkg/errors library.\n\n\tprev := locerr.Pos{\n\t\tOffset: 9,\n\t\tLine:   1,\n\t\tColumn: 10,\n\t\tFile:   src,\n\t}\n\n\terr = err.NoteAt(prev, \"Defined with 1 parameter\")\n\terr = err.NoteAt(prev, \"'foo' was defined as 'bool -\u003e int'\")\n\n\t// Finally you can see the result!\n\n\t// Get the error message as string. Note that this is only for non-Windows OS.\n\tfmt.Println(err)\n\n\t// Directly writes the error message into given file.\n\t// This supports Windows. Useful to output from stdout or stderr.\n\terr.PrintToFile(os.Stdout)\n}\n```\n\nAbove code should show the following output:\n\n```\nError: Calling 'foo' with wrong number of argument (at \u003cdummy\u003e:6:7)\n  Note: Defined with 1 parameter (at \u003cdummy\u003e:1:10)\n  Note: 'foo' was defined as 'bool -\u003e int' (at \u003cdummy\u003e:1:10)\n\n\u003e   foo(true,\n\u003e       42,\n\u003e       \"test\")\n\n```\n\n\u003cimg src=\"https://github.com/rhysd/ss/blob/master/locerr/output.png?raw=true\" width=\"547\" alt=\"output screenshot\"/\u003e\n\nLabels such as 'Error:' or 'Notes:' are colorized. Main error message is emphasized with bold font.\nAnd source code location information (file name, line and column) is added with gray text.\nIf the error has range information, the error shows code snippet which caused the error at the end\nof error message.\n\nIf you have only one position information rather than two, 'start' position and 'end' position,\n`ErrorAt` is available instead of `ErrorIn`. `ErrorAt` takes one `Pos` instance.\n\n```go\nerr := locerr.ErrorAt(start, \"Calling 'foo' with wrong number of argument\")\n```\n\nIn this case, line snippet is shown in error message. `pos.Line` is used to get line from source text.\n`fmt.Println(err)` will show the following.\n\n```\nError: Calling 'foo' with wrong number of argument (at \u003cdummy\u003e:6:7)\n\n\u003e   foo(true,\n\n```\n\n\n## Development\n\n### How to run tests\n\n```console\n$ go test ./\n```\n\nNote that `go test -v` may fail because color sequences are not assumed in tests.\n\n### How to run fuzzing test\n\nFuzzing test using [go-fuzz][].\n\n```console\n$ cd ./fuzz\n$ go-fuzz-build github.com/rhysd/locerr/fuzz\n$ go-fuzz -bin=./locerr_fuzz-fuzz.zip -workdir=fuzz\n```\n\nLast command starts fuzzing tests until stopped with `^C`. Every 3 seconds it reports the current\nresult. It makes 3 directories in `fuzz` directory as the result, `corpus`, `crashers` and\n`suppressions`. `crashers` contains the information about the crash caused by fuzzing.\n\n[locerr document]: https://godoc.org/github.com/rhysd/locerr\n[build badge]: https://travis-ci.org/rhysd/locerr.svg?branch=master\n[travis result]: https://travis-ci.org/rhysd/locerr\n[coverage status]: https://codecov.io/gh/rhysd/locerr/branch/master/graph/badge.svg\n[coverage result]: https://codecov.io/gh/rhysd/locerr\n[windows build badge]: https://ci.appveyor.com/api/projects/status/v4ghlgka6e6st2mn/branch/master?svg=true\n[appveyor result]: https://ci.appveyor.com/project/rhysd/locerr/branch/master\n[godoc badge]: https://godoc.org/github.com/rhysd/locerr?status.svg\n[go-fuzz]: https://github.com/dvyukov/go-fuzz\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhysd%2Flocerr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frhysd%2Flocerr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhysd%2Flocerr/lists"}