lpil / lpil/htmgrrrl

BUG Erlang Error when saxing

Open
#5 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Gleam
Stars
14
Forks
3
PR merge metrics
No merged PRs in 30d

Description

When I try this minimal example with the given URI:

```gleam
import gleam/hackney
import gleam/http/request
import gleam/result
import gleam/uri.{type Uri}
import htmgrrrl

pub fn fetch_link(uri: Uri) -> Int {
let assert Ok(req) = request.from_uri(uri)
let assert Ok(resp) = hackney.send(req)
case resp.status {
200 -> parse_data(resp.body)
_ -> -1
}
}

fn parse_data(body: String) -> Int {
let res =
htmgrrrl.sax(body, 0, fn(_, _, event) {
case event {
_ -> 1
}
})
result.unwrap(res, -2)
}

pub fn main() {
let assert Ok(uri) =
uri.parse("https://blog.flowblok.id.au/2013-02/shell-startup-scripts.html")
let i = fetch_link(uri)
echo i
}
```
I get the following error:

```
untime error: Erlang error

An error occurred outside of Gleam.

erlang:error(Badmap(Ok(1, [])))

stacktrace:
htmerl_sax_utf8.dispatch ./build/dev/erlang/htmerl/src/htmerl_sax_utf8.erl:2758
htmgrrrl_ffi.sax ./build/dev/erlang/htmgrrrl/_gleam_artefacts/htmgrrrl_ffi.erl:9
minimal_bug.fetch_link src/minimal_bug.gleam:19
minimal_bug.main src/minimal_bug.gleam:46
```
The same code works fine with other URLs. Being new to gleam (and erlang) I have no idea how I could help further. Let me know.

Here is an excerpt of my depency tree:

```
├── gleam_hackney v1.4.0
│ ├── gleam_http v4.3.0
│ │ └── gleam_stdlib v1.0.3
│ ├── gleam_stdlib v1.0.3
│ └── hackney v4.6.0
│ ├── certifi v2.17.0
│ ├── h2 v0.10.4
│ ├── idna v7.1.0
│ ├── mimerl v1.5.0
│ ├── parse_trans v3.4.2
│ ├── quic v1.7.1
│ ├── ssl_verify_fun v1.1.7
│ └── webtransport v0.4.3
│ ├── h2 v0.10.4
│ └── quic v1.7.1
├── gleam_http v4.3.0
│ └── gleam_stdlib v1.0.3
├── htmgrrrl v1.0.1
│ ├── gleam_stdlib v1.0.3
│ └── htmerl v0.2.1
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the minimal Gleam example with the failing URI and compare it with URLs that work. Start at htmerl_sax_utf8.erl:2758 and htmgrrrl_ffi.erl:9, using the stack trace to follow the SAX dispatch. Done means the example no longer raises Erlang Badmap and returns the parser result normally.

Written by the indexing model from the issue text.

Assessment

Tech stack
erlang
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.