@@ -16,6 +16,7 @@ import path from "path";
1616import { Uri , window , workspace } from "vscode" ;
1717import { ext } from "../extensionVariables" ;
1818import { QueryResultType } from "../models/queryResult" ;
19+ import { kdbOutputLog } from "./core" ;
1920
2021interface tblHeader {
2122 label : string ;
@@ -124,9 +125,17 @@ export function convertResultToVector(result: any): any[] {
124125export async function exportToCsv ( workspaceUri : Uri ) : Promise < void > {
125126 const timestamp = Date . now ( ) ;
126127 const fileName = `results-${ timestamp } .csv` ;
127- const filePath = Uri . parse ( path . join ( workspaceUri . fsPath , fileName ) ) ;
128- await workspace . fs . writeFile ( filePath , Buffer . from ( ext . resultPanelCSV ) ) ;
129- window . showTextDocument ( filePath , { preview : false } ) ;
128+ const filePath = Uri . file ( path . join ( workspaceUri . fsPath , fileName ) ) ;
129+
130+ try {
131+ await workspace . fs . writeFile ( filePath , Buffer . from ( ext . resultPanelCSV ) ) ;
132+ kdbOutputLog ( "file located at: " + filePath . fsPath , "INFO" ) ;
133+ window . showTextDocument ( filePath , { preview : false } ) ;
134+ } catch ( error ) {
135+ const errorMessage = error instanceof Error ? error . message : String ( error ) ;
136+ kdbOutputLog ( `Error writing file: ${ errorMessage } ` , "ERROR" ) ;
137+ window . showErrorMessage ( `Failed to write file: ${ errorMessage } ` ) ;
138+ }
130139}
131140
132141export function convertArrayOfArraysToObjects ( arr : any ) : any [ ] {
0 commit comments