Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

`FileHandle.metadata` is annotated to return a file handle, but returns the `Metadata`

未关闭
#70 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
64/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃

调研方向

Start with the FileHandle.metadata annotation and the _FileSystem_fstat kernel path, using the linked reproduction as the baseline. Run the provided gren make examples, then verify that metadata exposes FileSystem.Metadata fields and that the read example no longer accepts an incompatible handle or crashes.

由索引模型根据 Issue 内容生成。

描述

bug

Found against: gren 0.6.6, gren-lang/core 7.4.2, gren-lang/node 6.1.3, node 22
Reproduction: https://github.com/gilramir/gren-bug-reports/tree/main/2026-09-14-filehandle-metadata-type

FileSystem.FileHandle.metadata is annotated

metadata : ReadableFileHandle a -> Task FileSystem.Error (ReadableFileHandle FileSystem.Metadata)

but its kernel code, _FileSystem_fstat, succeeds with the Metadata record
itself. So reading a field of the result, the one thing metadata is for, does
not compile, and passing the result to FileHandle.read, which does compile,
crashes the program instead of failing the task.

Reproduction

gren.json dependencies: gren-lang/core 7.4.2, gren-lang/node 6.1.3. Save as src/Main.gren, which reads the size of gren.json through a file handle. Build with gren make Main --output=app:

module Main exposing (main)
             
import FileSystem       
import FileSystem.FileHandle as FileHandle                 
import FileSystem.Path as Path
import Init                                      
import Node
import Stream                                                                  
import Task
                              
 main : Node.SimpleProgram a                                                 
main =                                                                     
    Node.defineSimpleProgram <| \env ->
        Init.await FileSystem.initialize <| \fs ->
            Node.endSimpleProgram
                (FileHandle.openForRead fs (Path.fromPosixString "gren.json")
                    |> Task.andThen FileHandle.metadata
                    |> Task.map (\m -> "byteSize = " ++ String.fromInt m.byteSize)
                    |> Task.onError (\e -> Task.succeed (FileSystem.errorToString e))
                    |> Task.andThen (\line -> Stream.writeLineAsBytes line env.stdout)
                    |> Task.onError (\_ -> Task.succeed env.stdout)
                )

Output:

$ gren make Main --output=app
Compiling ...-- TYPE MISMATCH ------------------------------------------------- src/Main.gren

This function cannot handle the argument sent through the (|>) pipe:

17|                 (FileHandle.openForRead fs (Path.fromPosixString "gren.json")
18|                     |> Task.andThen FileHandle.metadata
19|                     |> Task.map (\m -> "byteSize = " ++ String.fromInt m.byteSize)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The argument is:

    Task.Task
        FileSystem.Error
        (FileHandle.ReadableFileHandle FileSystem.Metadata)

But (|>) is piping it to a function that expects:

    Task.Task FileSystem.Error { a | byteSize : Int }

Detected problems in 1 module.

src/ReadFromMetadata.gren is the same program with Task.map (\m -> ...)
replaced by what the annotation allows:

                    |> Task.andThen FileHandle.read
                    |> Task.map (\_ -> "read from the metadata")

It compiles, and crashes:

$ gren make ReadFromMetadata --output=app && node app
node:internal/errors:540
      throw error;
      ^

TypeError [ERR_INVALID_ARG_TYPE]: The "fd" argument must be of type number. Received undefined
    at Object.read (node:fs:604:8)
    at _FileSystem_readHelper (/path/to/app:3260:6)
    at Object.b (/path/to/app:3239:5)
    at _Scheduler_step (/path/to/app:298:25)
    at _Scheduler_enqueue (/path/to/app:279:7)
    at /path/to/app:300:9
    at /path/to/app:3484:9
    at FSReqCallback.oncomplete (node:fs:197:5) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Node.js v22.23.2
主要语言
JavaScript
星标
13
派生
6
平均合并
4 天 10 小时
30 天内合并 PR
4

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

gren-lang/node 的其他 Issue

查看 gren-lang/node 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。