Skip to content

Commit 9ff366f

Browse files
committed
Fix error message when reading from closed file
1 parent 862fc05 commit 9ff366f

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIONodes.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import static com.oracle.graal.python.nodes.ErrorMessages.IO_STREAM_INVALID_POS;
5757
import static com.oracle.graal.python.nodes.ErrorMessages.REENTRANT_CALL_INSIDE_P;
5858
import static com.oracle.graal.python.nodes.ErrorMessages.SHUTDOWN_POSSIBLY_DUE_TO_DAEMON_THREADS;
59+
import static com.oracle.graal.python.nodes.ErrorMessages.S_OF_CLOSED_FILE;
5960
import static com.oracle.graal.python.nodes.ErrorMessages.S_TO_CLOSED_FILE;
6061
import static com.oracle.graal.python.runtime.exception.PythonErrorType.IOUnsupportedOperation;
6162
import static com.oracle.graal.python.runtime.exception.PythonErrorType.OSError;
@@ -94,9 +95,11 @@ public class BufferedIONodes {
9495
abstract static class CheckIsClosedNode extends PNodeWithContext {
9596

9697
private final String method;
98+
private final String messageFmt;
9799

98100
public CheckIsClosedNode(String method) {
99101
this.method = method;
102+
this.messageFmt = IONodes.WRITE.equals(method) ? S_TO_CLOSED_FILE : S_OF_CLOSED_FILE;
100103
}
101104

102105
public abstract boolean execute(VirtualFrame frame, PBuffered self);
@@ -107,7 +110,7 @@ boolean isClosedBuffered(VirtualFrame frame, PBuffered self,
107110
@Cached IsClosedNode isClosedNode,
108111
@Cached ConditionProfile isError) {
109112
if (isError.profile(isClosedNode.execute(frame, self))) {
110-
throw raiseNode.raise(PythonBuiltinClassType.ValueError, S_TO_CLOSED_FILE, method);
113+
throw raiseNode.raise(PythonBuiltinClassType.ValueError, messageFmt, method);
111114
}
112115
return false;
113116
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,7 @@ public abstract class ErrorMessages {
852852
public static final String FILE_NOT_OPEN_FOR_S = "File not open for %s";
853853
public static final String UNBOUNDED_READ_RETURNED_MORE_BYTES = "unbounded read returned more bytes than a Python bytes object can hold";
854854
public static final String INVALID_MODE_S = "invalid mode: %s";
855+
public static final String S_OF_CLOSED_FILE = "%s of closed file";
855856
public static final String S_TO_CLOSED_FILE = "%s to closed file";
856857
public static final String NOT_POSSIBLE_TO_SET_THE_ENCODING_OR = "It is not possible to set the encoding or newline of stream after the first read";
857858
public static final String NOT_WRITABLE = "not writable";

0 commit comments

Comments
 (0)