Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework Supply chain chapter: solution does not handle errors properly because of the specifics of the files API #71

Closed
greenfork opened this issue Dec 29, 2023 · 0 comments · Fixed by #73
Assignees

Comments

@greenfork
Copy link
Contributor

The currently listed solution is:

use "files"

actor Main
  new create(env: Env) =>
    try
      let dir = FilePath.mkdtemp(FileAuth(env.root))?
      let writer = TempWriter(dir, "free-candy.txt")
    else
      env.err.print("Couldn't create temporary directory")
    end

actor TempWriter
  let _file: File

  new create(dir: FilePath, file_name: String) =>
    _file = File(dir)

  be record(it: String) =>
    _file.write(it)

The constructor create creates a file descriptor but does not check for errors, the correct code to check for errors would be:

  new create(dir: FilePath, file_name: String) =>
    _file = File(dir)
    if not (_file.errno() is FileOK) then error end

But it is not possible to do so because an actor constructor cannot fail, and actually defeats the purpose of this chapter because the chapter advises to do error handling before constructing an actor.

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Dec 29, 2023
@SeanTAllen SeanTAllen self-assigned this Jan 9, 2024
@SeanTAllen SeanTAllen removed the discuss during sync Should be discussed during an upcoming sync label Jan 9, 2024
SeanTAllen added a commit that referenced this issue Jan 10, 2024
A user pointed out that we weren't address the fact that `File` can
fail and that you need to check `errno()` to see if it worked. This
makes the pattern incomplete and misleading.

When I was addressing this, I noticed that when I originally wrote
the pattern, I was trying to write the temp directory without creating
a file in it.

Both issues have been addressed in this update.

Closes #71
SeanTAllen added a commit that referenced this issue Jan 10, 2024
A user pointed out that we weren't address the fact that `File` can
fail and that you need to check `errno()` to see if it worked. This
makes the pattern incomplete and misleading.

When I was addressing this, I noticed that when I originally wrote
the pattern, I was trying to write the temp directory without creating
a file in it.

Both issues have been addressed in this update.

Closes #71
SeanTAllen added a commit that referenced this issue Jan 16, 2024
* Address correctness issues in Supply Chain pattern

A user pointed out that we weren't address the fact that `File` can
fail and that you need to check `errno()` to see if it worked. This
makes the pattern incomplete and misleading.

When I was addressing this, I noticed that when I originally wrote
the pattern, I was trying to write the temp directory without creating
a file in it.

Both issues have been addressed in this update.

Closes #71
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants