#error.NotOpenForWriting when trying to flush a buffer

1 messages · Page 1 of 1 (latest)

graceful flower
#

Hi. I keep getting an error.NotOpenForWriting when trying to flush a buffered writer created from a File handle. That is: self.buff.flush() catch |e| {...} keeps triggering a error.NotOpenForWriting . self.buff is a std.io.BufferedWriter created from an actual file. Any ideas or suggestions?
Many thanks!

cold tartan
#

Can you share the code that causes this?
First guess, did you close the file before calling flush?

acoustic oracle
#

How did you open the file?

graceful flower
#

The file is opened like so: try std.fs.cwd().createFile(filename, .{}).
Closing is handled using a defer statement so it doesn't happen while the file is still in use.

acoustic oracle
#

Hmm, strange

#

Could you share the full code snippet?

graceful flower
#

Ha, you're absolutely right @cold tartan .
I actually had defer in a premature if condition block 😅
Removing that fixes it. Thanks everyone!