mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Show an error in cell output when trying to load an unsupported output type. (#19693)
This commit is contained in:
@@ -8,6 +8,7 @@ import { nb } from 'azdata';
|
|||||||
import { JSONObject, isPrimitive } from 'sql/workbench/services/notebook/common/jsonext';
|
import { JSONObject, isPrimitive } from 'sql/workbench/services/notebook/common/jsonext';
|
||||||
import { nbformat } from 'sql/workbench/services/notebook/common/nbformat';
|
import { nbformat } from 'sql/workbench/services/notebook/common/nbformat';
|
||||||
import { MimeModel } from 'sql/workbench/services/notebook/browser/outputs/mimemodel';
|
import { MimeModel } from 'sql/workbench/services/notebook/browser/outputs/mimemodel';
|
||||||
|
import * as nls from 'vs/nls';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A multiline string.
|
* A multiline string.
|
||||||
@@ -46,6 +47,8 @@ export function getData(output: nb.ICellOutput): JSONObject {
|
|||||||
} else if (output.evalue) {
|
} else if (output.evalue) {
|
||||||
bundle['application/vnd.jupyter.stderr'] = output.ename ? `${output.ename}: ${output.evalue}` : `${output.evalue}`;
|
bundle['application/vnd.jupyter.stderr'] = output.ename ? `${output.ename}: ${output.evalue}` : `${output.evalue}`;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
bundle['application/vnd.jupyter.stderr'] = nls.localize('notebookInvalidOutputTypeError', "Output type '{0}' not recognized.", output.output_type);
|
||||||
}
|
}
|
||||||
return convertBundle(bundle);
|
return convertBundle(bundle);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,20 @@ suite('OutputProcessor functions', function (): void {
|
|||||||
verifyGetDataForStreamOutput(output);
|
verifyGetDataForStreamOutput(output);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unknown output types
|
||||||
|
test('Should report an error for unknown output types', () => {
|
||||||
|
const output = {
|
||||||
|
output_type: 'unknown',
|
||||||
|
data: {
|
||||||
|
'text/html': 'Test text'
|
||||||
|
},
|
||||||
|
metadata: {}
|
||||||
|
};
|
||||||
|
const result = op.getData(<any>output);
|
||||||
|
assert(result['application/vnd.jupyter.stderr'] !== undefined, 'Should set an error message after receiving unknown output type.');
|
||||||
|
assert(result['text/html'] === undefined, 'Should not add any data after receiving unknown output type.');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
suite('getMetadata', function (): void {
|
suite('getMetadata', function (): void {
|
||||||
|
|||||||
@@ -155,8 +155,8 @@ namespace v4 {
|
|||||||
traceback: output.traceback
|
traceback: output.traceback
|
||||||
};
|
};
|
||||||
default:
|
default:
|
||||||
// Should never get here
|
// Unknown type, so return as is. If it's unsupported, then an error will be shown later when trying to render it.
|
||||||
throw new TypeError(localize('unrecognizedOutput', "Output type {0} not recognized", (<any>output).output_type));
|
return output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,6 +272,7 @@ namespace v3 {
|
|||||||
name: name,
|
name: name,
|
||||||
text: v4.demultiline(output.text)
|
text: v4.demultiline(output.text)
|
||||||
};
|
};
|
||||||
|
case 'error':
|
||||||
case 'pyerr':
|
case 'pyerr':
|
||||||
return <nb.IErrorResult>{
|
return <nb.IErrorResult>{
|
||||||
output_type: OutputTypes.Error,
|
output_type: OutputTypes.Error,
|
||||||
@@ -280,7 +281,8 @@ namespace v3 {
|
|||||||
traceback: output.traceback
|
traceback: output.traceback
|
||||||
};
|
};
|
||||||
default:
|
default:
|
||||||
throw new TypeError(localize('unrecognizedOutputType', "Output type {0} not recognized", output.output_type));
|
// Unknown type, so return as is. If it's unsupported, then an error will be shown later when trying to render it.
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user