From e04fab7a970da0647e767dac38a4dd92b28d0a57 Mon Sep 17 00:00:00 2001 From: "Alexander.Kass" Date: Tue, 9 Sep 2025 11:51:01 +0300 Subject: [PATCH] dw: receive errors during execution GitOrigin-RevId: d8c41efe046684dbc0c4b1ee21298787b6edf6fe --- .../protocol/PythonConsoleBackendService.java | 962 ++++++++++++++++++ .../_pydev_bundle/pydev_console_utils.py | 12 + .../pydev/_pydevd_bundle/pydevd_tables.py | 9 +- .../pydev/pydev_console/console.thrift | 2 + .../console/PydevConsoleCommunication.java | 25 + 5 files changed, 1009 insertions(+), 1 deletion(-) diff --git a/python/gen/com/jetbrains/python/console/protocol/PythonConsoleBackendService.java b/python/gen/com/jetbrains/python/console/protocol/PythonConsoleBackendService.java index ad9d84ce6c31..05d494048e39 100644 --- a/python/gen/com/jetbrains/python/console/protocol/PythonConsoleBackendService.java +++ b/python/gen/com/jetbrains/python/console/protocol/PythonConsoleBackendService.java @@ -96,6 +96,8 @@ public class PythonConsoleBackendService { */ public void loadFullValue(int seq, java.util.List variables) throws PythonUnhandledException, org.apache.thrift.TException; + public java.lang.String execRaw(java.lang.String command) throws PythonUnhandledException, org.apache.thrift.TException; + public java.lang.String execTableCommand(java.lang.String tableVariable, java.lang.String commandType, java.lang.String startIndex, java.lang.String endIndex, java.lang.String format) throws PythonUnhandledException, PythonTableException, org.apache.thrift.TException; public java.lang.String execTableImageCommand(java.lang.String tableVariable, java.lang.String commandType, java.lang.String offset, java.lang.String imageId) throws PythonUnhandledException, PythonTableException, org.apache.thrift.TException; @@ -136,6 +138,8 @@ public class PythonConsoleBackendService { public void loadFullValue(int seq, java.util.List variables, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + public void execRaw(java.lang.String command, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + public void execTableCommand(java.lang.String tableVariable, java.lang.String commandType, java.lang.String startIndex, java.lang.String endIndex, java.lang.String format, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; public void execTableImageCommand(java.lang.String tableVariable, java.lang.String commandType, java.lang.String offset, java.lang.String imageId, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; @@ -575,6 +579,33 @@ public class PythonConsoleBackendService { return; } + @Override + public java.lang.String execRaw(java.lang.String command) throws PythonUnhandledException, org.apache.thrift.TException + { + send_execRaw(command); + return recv_execRaw(); + } + + public void send_execRaw(java.lang.String command) throws org.apache.thrift.TException + { + execRaw_args args = new execRaw_args(); + args.setCommand(command); + sendBase("execRaw", args); + } + + public java.lang.String recv_execRaw() throws PythonUnhandledException, org.apache.thrift.TException + { + execRaw_result result = new execRaw_result(); + receiveBase(result, "execRaw"); + if (result.isSetSuccess()) { + return result.success; + } + if (result.unhandledException != null) { + throw result.unhandledException; + } + throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "execRaw failed: unknown result"); + } + @Override public java.lang.String execTableCommand(java.lang.String tableVariable, java.lang.String commandType, java.lang.String startIndex, java.lang.String endIndex, java.lang.String format) throws PythonUnhandledException, PythonTableException, org.apache.thrift.TException { @@ -1259,6 +1290,41 @@ public class PythonConsoleBackendService { } } + @Override + public void execRaw(java.lang.String command, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + checkReady(); + execRaw_call method_call = new execRaw_call(command, resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class execRaw_call extends org.apache.thrift.async.TAsyncMethodCall { + private java.lang.String command; + public execRaw_call(java.lang.String command, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + super(client, protocolFactory, transport, resultHandler, false); + this.command = command; + } + + @Override + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("execRaw", org.apache.thrift.protocol.TMessageType.CALL, 0)); + execRaw_args args = new execRaw_args(); + args.setCommand(command); + args.write(prot); + prot.writeMessageEnd(); + } + + @Override + public java.lang.String getResult() throws PythonUnhandledException, PythonTableException, org.apache.thrift.TException { + if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { + throw new java.lang.IllegalStateException("Method call not finished!"); + } + org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); + org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); + return (new Client(prot)).recv_execRaw(); + } + } + @Override public void execTableCommand(java.lang.String tableVariable, java.lang.String commandType, java.lang.String startIndex, java.lang.String endIndex, java.lang.String format, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { checkReady(); @@ -1886,6 +1952,38 @@ public class PythonConsoleBackendService { } } + public static class execRaw extends org.apache.thrift.ProcessFunction { + public execRaw() { + super("execRaw"); + } + + @Override + public execRaw_args getEmptyArgsInstance() { + return new execRaw_args(); + } + + @Override + public boolean isOneway() { + return false; + } + + @Override + protected boolean rethrowUnhandledExceptions() { + return false; + } + + @Override + public execRaw_result getResult(I iface, execRaw_args args) throws org.apache.thrift.TException { + execRaw_result result = new execRaw_result(); + try { + result.success = iface.execRaw(args.command); + } catch (PythonUnhandledException unhandledException) { + result.unhandledException = unhandledException; + } + return result; + } + } + public static class execTableCommand extends org.apache.thrift.ProcessFunction { public execTableCommand() { super("execTableCommand"); @@ -17387,6 +17485,870 @@ public class PythonConsoleBackendService { } } + @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) + public static class execRaw_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("execRaw_args"); + + private static final org.apache.thrift.protocol.TField COMMAND_FIELD_DESC = new org.apache.thrift.protocol.TField("command", org.apache.thrift.protocol.TType.STRING, (short)1); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new execRaw_argsStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new execRaw_argsTupleSchemeFactory(); + + public @org.apache.thrift.annotation.Nullable java.lang.String command; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + COMMAND((short)1, "command"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // COMMAND + return COMMAND; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + @Override + public short getThriftFieldId() { + return _thriftId; + } + + @Override + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.COMMAND, new org.apache.thrift.meta_data.FieldMetaData("command", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(execRaw_args.class, metaDataMap); + } + + public execRaw_args() { + } + + public execRaw_args( + java.lang.String command) + { + this(); + this.command = command; + } + + /** + * Performs a deep copy on other. + */ + public execRaw_args(execRaw_args other) { + if (other.isSetCommand()) { + this.command = other.command; + } + } + + @Override + public execRaw_args deepCopy() { + return new execRaw_args(this); + } + + @Override + public void clear() { + this.command = null; + } + + @org.apache.thrift.annotation.Nullable + public java.lang.String getCommand() { + return this.command; + } + + public execRaw_args setCommand(@org.apache.thrift.annotation.Nullable java.lang.String command) { + this.command = command; + return this; + } + + public void unsetCommand() { + this.command = null; + } + + /** Returns true if field command is set (has been assigned a value) and false otherwise */ + public boolean isSetCommand() { + return this.command != null; + } + + public void setCommandIsSet(boolean value) { + if (!value) { + this.command = null; + } + } + + @Override + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) { + switch (field) { + case COMMAND: + if (value == null) { + unsetCommand(); + } else { + setCommand((java.lang.String)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + @Override + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case COMMAND: + return getCommand(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + @Override + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case COMMAND: + return isSetCommand(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that instanceof execRaw_args) + return this.equals((execRaw_args)that); + return false; + } + + public boolean equals(execRaw_args that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_command = true && this.isSetCommand(); + boolean that_present_command = true && that.isSetCommand(); + if (this_present_command || that_present_command) { + if (!(this_present_command && that_present_command)) + return false; + if (!this.command.equals(that.command)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetCommand()) ? 131071 : 524287); + if (isSetCommand()) + hashCode = hashCode * 8191 + command.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(execRaw_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.compare(isSetCommand(), other.isSetCommand()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetCommand()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.command, other.command); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + @Override + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + @Override + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("execRaw_args("); + boolean first = true; + + sb.append("command:"); + if (this.command == null) { + sb.append("null"); + } else { + sb.append(this.command); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class execRaw_argsStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + @Override + public execRaw_argsStandardScheme getScheme() { + return new execRaw_argsStandardScheme(); + } + } + + private static class execRaw_argsStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + @Override + public void read(org.apache.thrift.protocol.TProtocol iprot, execRaw_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // COMMAND + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.command = iprot.readString(); + struct.setCommandIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + @Override + public void write(org.apache.thrift.protocol.TProtocol oprot, execRaw_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.command != null) { + oprot.writeFieldBegin(COMMAND_FIELD_DESC); + oprot.writeString(struct.command); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class execRaw_argsTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + @Override + public execRaw_argsTupleScheme getScheme() { + return new execRaw_argsTupleScheme(); + } + } + + private static class execRaw_argsTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, execRaw_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetCommand()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetCommand()) { + oprot.writeString(struct.command); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, execRaw_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + struct.command = iprot.readString(); + struct.setCommandIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + + @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) + public static class execRaw_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("execRaw_result"); + + private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.STRING, (short)0); + private static final org.apache.thrift.protocol.TField UNHANDLED_EXCEPTION_FIELD_DESC = new org.apache.thrift.protocol.TField("unhandledException", org.apache.thrift.protocol.TType.STRUCT, (short)1); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new execRaw_resultStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new execRaw_resultTupleSchemeFactory(); + + public @org.apache.thrift.annotation.Nullable java.lang.String success; // required + public @org.apache.thrift.annotation.Nullable PythonUnhandledException unhandledException; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + SUCCESS((short)0, "success"), + UNHANDLED_EXCEPTION((short)1, "unhandledException"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 0: // SUCCESS + return SUCCESS; + case 1: // UNHANDLED_EXCEPTION + return UNHANDLED_EXCEPTION; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + @Override + public short getThriftFieldId() { + return _thriftId; + } + + @Override + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + tmpMap.put(_Fields.UNHANDLED_EXCEPTION, new org.apache.thrift.meta_data.FieldMetaData("unhandledException", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, PythonUnhandledException.class))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(execRaw_result.class, metaDataMap); + } + + public execRaw_result() { + } + + public execRaw_result( + java.lang.String success, + PythonUnhandledException unhandledException) + { + this(); + this.success = success; + this.unhandledException = unhandledException; + } + + /** + * Performs a deep copy on other. + */ + public execRaw_result(execRaw_result other) { + if (other.isSetSuccess()) { + this.success = other.success; + } + if (other.isSetUnhandledException()) { + this.unhandledException = new PythonUnhandledException(other.unhandledException); + } + } + + @Override + public execRaw_result deepCopy() { + return new execRaw_result(this); + } + + @Override + public void clear() { + this.success = null; + this.unhandledException = null; + } + + @org.apache.thrift.annotation.Nullable + public java.lang.String getSuccess() { + return this.success; + } + + public execRaw_result setSuccess(@org.apache.thrift.annotation.Nullable java.lang.String success) { + this.success = success; + return this; + } + + public void unsetSuccess() { + this.success = null; + } + + /** Returns true if field success is set (has been assigned a value) and false otherwise */ + public boolean isSetSuccess() { + return this.success != null; + } + + public void setSuccessIsSet(boolean value) { + if (!value) { + this.success = null; + } + } + + @org.apache.thrift.annotation.Nullable + public PythonUnhandledException getUnhandledException() { + return this.unhandledException; + } + + public execRaw_result setUnhandledException(@org.apache.thrift.annotation.Nullable PythonUnhandledException unhandledException) { + this.unhandledException = unhandledException; + return this; + } + + public void unsetUnhandledException() { + this.unhandledException = null; + } + + /** Returns true if field unhandledException is set (has been assigned a value) and false otherwise */ + public boolean isSetUnhandledException() { + return this.unhandledException != null; + } + + public void setUnhandledExceptionIsSet(boolean value) { + if (!value) { + this.unhandledException = null; + } + } + + @Override + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) { + switch (field) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((java.lang.String)value); + } + break; + + case UNHANDLED_EXCEPTION: + if (value == null) { + unsetUnhandledException(); + } else { + setUnhandledException((PythonUnhandledException)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + @Override + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case SUCCESS: + return getSuccess(); + + case UNHANDLED_EXCEPTION: + return getUnhandledException(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + @Override + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case SUCCESS: + return isSetSuccess(); + case UNHANDLED_EXCEPTION: + return isSetUnhandledException(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that instanceof execRaw_result) + return this.equals((execRaw_result)that); + return false; + } + + public boolean equals(execRaw_result that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_success = true && this.isSetSuccess(); + boolean that_present_success = true && that.isSetSuccess(); + if (this_present_success || that_present_success) { + if (!(this_present_success && that_present_success)) + return false; + if (!this.success.equals(that.success)) + return false; + } + + boolean this_present_unhandledException = true && this.isSetUnhandledException(); + boolean that_present_unhandledException = true && that.isSetUnhandledException(); + if (this_present_unhandledException || that_present_unhandledException) { + if (!(this_present_unhandledException && that_present_unhandledException)) + return false; + if (!this.unhandledException.equals(that.unhandledException)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetSuccess()) ? 131071 : 524287); + if (isSetSuccess()) + hashCode = hashCode * 8191 + success.hashCode(); + + hashCode = hashCode * 8191 + ((isSetUnhandledException()) ? 131071 : 524287); + if (isSetUnhandledException()) + hashCode = hashCode * 8191 + unhandledException.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(execRaw_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.compare(isSetSuccess(), other.isSetSuccess()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSuccess()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, other.success); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.compare(isSetUnhandledException(), other.isSetUnhandledException()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetUnhandledException()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.unhandledException, other.unhandledException); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + @Override + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("execRaw_result("); + boolean first = true; + + sb.append("success:"); + if (this.success == null) { + sb.append("null"); + } else { + sb.append(this.success); + } + first = false; + if (!first) sb.append(", "); + sb.append("unhandledException:"); + if (this.unhandledException == null) { + sb.append("null"); + } else { + sb.append(this.unhandledException); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class execRaw_resultStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + @Override + public execRaw_resultStandardScheme getScheme() { + return new execRaw_resultStandardScheme(); + } + } + + private static class execRaw_resultStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + @Override + public void read(org.apache.thrift.protocol.TProtocol iprot, execRaw_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 0: // SUCCESS + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.success = iprot.readString(); + struct.setSuccessIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 1: // UNHANDLED_EXCEPTION + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.unhandledException = new PythonUnhandledException(); + struct.unhandledException.read(iprot); + struct.setUnhandledExceptionIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + @Override + public void write(org.apache.thrift.protocol.TProtocol oprot, execRaw_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.success != null) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + oprot.writeString(struct.success); + oprot.writeFieldEnd(); + } + if (struct.unhandledException != null) { + oprot.writeFieldBegin(UNHANDLED_EXCEPTION_FIELD_DESC); + struct.unhandledException.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class execRaw_resultTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + @Override + public execRaw_resultTupleScheme getScheme() { + return new execRaw_resultTupleScheme(); + } + } + + private static class execRaw_resultTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, execRaw_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetSuccess()) { + optionals.set(0); + } + if (struct.isSetUnhandledException()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetSuccess()) { + oprot.writeString(struct.success); + } + if (struct.isSetUnhandledException()) { + struct.unhandledException.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, execRaw_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.success = iprot.readString(); + struct.setSuccessIsSet(true); + } + if (incoming.get(1)) { + struct.unhandledException = new PythonUnhandledException(); + struct.unhandledException.read(iprot); + struct.setUnhandledExceptionIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) public static class execTableCommand_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("execTableCommand_args"); diff --git a/python/helpers/pydev/_pydev_bundle/pydev_console_utils.py b/python/helpers/pydev/_pydev_bundle/pydev_console_utils.py index 9feecacfd360..ecf6702cabd8 100644 --- a/python/helpers/pydev/_pydev_bundle/pydev_console_utils.py +++ b/python/helpers/pydev/_pydev_bundle/pydev_console_utils.py @@ -13,6 +13,7 @@ from _pydevd_bundle.pydevd_comm import InternalDataViewerAction from _pydevd_bundle.pydevd_constants import IS_JYTHON, dict_iter_items from _pydevd_bundle.pydevd_tables import exec_table_command from _pydevd_bundle.pydevd_tables import exec_image_table_command +from _pydevd_bundle.pydevd_tables import exec_raw from _pydevd_bundle.pydevd_user_type_renderers import parse_set_type_renderers_message from pydev_console.pydev_protocol import CompletionOption, CompletionOptionType, \ PythonUnhandledException, PythonTableException @@ -432,6 +433,17 @@ class BaseInterpreterInterface(BaseCodeExecutor): if not success: raise PythonTableException(str(res)) + # + def execRaw(self, command): + try: + success, res = exec_raw(command, self.get_namespace(), self.get_namespace()) + if success: + return res + except: + traceback.print_exc() + raise PythonUnhandledException(traceback.format_exc()) + if not success: + raise PythonUnhandledException(str(res)) # def execTableImageCommand(self, command, command_type, offset, image_id): diff --git a/python/helpers/pydev/_pydevd_bundle/pydevd_tables.py b/python/helpers/pydev/_pydevd_bundle/pydevd_tables.py index 2f06b5d4c5c4..a02beea4afb5 100644 --- a/python/helpers/pydev/_pydevd_bundle/pydevd_tables.py +++ b/python/helpers/pydev/_pydevd_bundle/pydevd_tables.py @@ -5,7 +5,7 @@ from _pydevd_bundle import pydevd_vars from _pydevd_bundle.pydevd_constants import NEXT_VALUE_SEPARATOR from _pydevd_bundle.pydevd_xml import ExceptionOnEvaluate from _pydevd_bundle.tables.images.pydevd_image_loader import load_image_chunk - +from _pydev_bundle.pydev_imports import Exec class TableCommandType: DF_INFO = "DF_INFO" @@ -42,6 +42,13 @@ def exec_image_table_command(init_command, command_type, offset, image_id, f_glo return True, load_image_chunk(offset, image_id) +def exec_raw(command, f_globals, f_locals): + try: + res = Exec(command, f_globals, f_locals) + return True, str(res) + except: + return False, pydevd_vars.get_eval_exception_msg(command, f_locals).result + def exec_table_command(init_command, command_type, start_index, end_index, format, f_globals, f_locals): table = pydevd_vars.eval_in_context(init_command, f_globals, f_locals) diff --git a/python/helpers/pydev/pydev_console/console.thrift b/python/helpers/pydev/pydev_console/console.thrift index 2cd54ceccceb..522d1e1890a2 100644 --- a/python/helpers/pydev/pydev_console/console.thrift +++ b/python/helpers/pydev/pydev_console/console.thrift @@ -202,6 +202,8 @@ service PythonConsoleBackendService { */ void loadFullValue(1: LoadFullValueRequestSeq seq, 2: list variables) throws (1: PythonUnhandledException unhandledException), + string execRaw(1: string command) throws (1: PythonUnhandledException unhandledException) + string execTableCommand(1: string tableVariable, 2: string commandType, 3: string startIndex, 4: string endIndex, 5: string format) throws (1: PythonUnhandledException unhandledException, 2: PythonTableException tableException) string execTableImageCommand(1: string tableVariable, 2: string commandType, 3: string offset, 4: string imageId) throws (1: PythonUnhandledException unhandledException, 2: PythonTableException tableException) diff --git a/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java b/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java index b65abe41e6a3..7045e8dd4bdb 100644 --- a/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java +++ b/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java @@ -46,6 +46,7 @@ import com.jetbrains.python.psi.PyElementGenerator; import com.jetbrains.python.tables.TableCommandParameters; import com.jetbrains.python.tables.TableCommandType; import org.apache.thrift.TException; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; @@ -366,6 +367,30 @@ public abstract class PydevConsoleCommunication extends AbstractConsoleCommunica } } + @ApiStatus.Internal + public String execRaw(String command) throws PyDebuggerException { + if (!isCommunicationClosed()) { + return executeBackgroundTask( + () -> { + try { + return getPythonConsoleBackendClient().execRaw(command); + } + catch (PythonUnhandledException e) { + throw new PyDebuggerException(e.traceback); + } + finally { + notifyCommandExecuted(false); + } + }, + true, + createRuntimeMessage(PyBundle.message("console.getting.table.data")), + PyBundle.message("console.table.failed.to.load") + ); + } + else { + return null; + } + } @Override public String execTableCommand(String command, TableCommandType commandType, TableCommandParameters tableCommandParameters) throws PyDebuggerException { if (!isCommunicationClosed()) {