TypeError: Cannot read properties of undefined (reading '0') using client.openSession();

Abierto
#264 8 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
next.js, node.js, sql, typescript

Línea de trabajo

Empieza reproduciendo el fallo de app/api/databricks-test/route.ts con el alias de webpack en next.config.js y compáralo después con examples/usage.js. Sigue la ruta de openSession a través de @databricks/sql y node-int64/Int64.js, y verifica que el workaround de lz4 ya no provoque el TypeError. Se considera terminado cuando la sesión se abre, la consulta de ejemplo devuelve resultados y cada rama del route-handler devuelve una respuesta.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Previously working code causing a TypeError: Cannot read properties of undefined (reading '0'). This code is from the following example: https://github.com/databricks/databricks-sql-nodejs/blob/HEAD/examples/usage.js

const { DBSQLClient } = require('@databricks/sql');
import { DBSQLLogger, LogLevel } from '@databricks/sql';
import { NextResponse } from "next/server";



export async function POST(){

const logger = new DBSQLLogger({ filepath: 'log.txt', level: LogLevel.debug });
    
    
const client = new DBSQLClient({ logger: logger });
console.log("CREATED CLIENT");

client
  .connect({
    host: process.env.DATABRICKS_SERVER_HOSTNAME,
    path: process.env.DATABRICKS_HTTP_PATH,
    token: process.env.DATABRICKS_TOKEN,
  })
  .then(async (client: { openSession: () => any; close: () => any; }) => {
    const session = await client.openSession();
    console.log("SESSION CREATED");

    const queryOperation = await session.executeStatement('SELECT "Hello, World!"');
    const result = await queryOperation.fetchAll();
    await queryOperation.close();

    console.table(result);

    await session.close();
    await client.close();
    return NextResponse.json(result);
  })
  .catch((error: any) => {
    console.log(error);
    if (error instanceof Error) {  
        console.error("Error executing query: ", error);  
        return NextResponse.json(  
          { error: "Failed to execute query: ", details: error.message },  
          { status: 500 }  
        );  
      }  
  });
}

Console output:

{"level":"info","message":"Created DBSQLClient"}
CREATED CLIENT
TypeError: Cannot read properties of undefined (reading '0')
    at isInsideNodeModules (node:internal/util:508:17)
    at showFlaggedDeprecation (node:buffer:178:8)
    at new Buffer (node:buffer:266:3)
    at new module.exports (webpack-internal:///(rsc)/./node_modules/node-int64/Int64.js:65:34)
    at DBSQLClient.eval (webpack-internal:///(rsc)/./node_modules/@databricks/sql/dist/DBSQLClient.js:197:111)
    at Generator.next (<anonymous>)
    at eval (webpack-internal:///(rsc)/./node_modules/@databricks/sql/dist/DBSQLClient.js:31:71)
    at new Promise (<anonymous>)
    at __awaiter (webpack-internal:///(rsc)/./node_modules/@databricks/sql/dist/DBSQLClient.js:27:12)
    at DBSQLClient.openSession (webpack-internal:///(rsc)/./node_modules/@databricks/sql/dist/DBSQLClient.js:196:16)
    at eval (webpack-internal:///(rsc)/./app/api/databricks-test/route.ts:25:38)
Error executing query:  TypeError: Cannot read properties of undefined (reading '0')
    at isInsideNodeModules (node:internal/util:508:17)
    at showFlaggedDeprecation (node:buffer:178:8)
    at new Buffer (node:buffer:266:3)
    at new module.exports (webpack-internal:///(rsc)/./node_modules/node-int64/Int64.js:65:34)
    at DBSQLClient.eval (webpack-internal:///(rsc)/./node_modules/@databricks/sql/dist/DBSQLClient.js:197:111)
    at Generator.next (<anonymous>)
    at eval (webpack-internal:///(rsc)/./node_modules/@databricks/sql/dist/DBSQLClient.js:31:71)
    at new Promise (<anonymous>)
    at __awaiter (webpack-internal:///(rsc)/./node_modules/@databricks/sql/dist/DBSQLClient.js:27:12)
    at DBSQLClient.openSession (webpack-internal:///(rsc)/./node_modules/@databricks/sql/dist/DBSQLClient.js:196:16)
    at eval (webpack-internal:///(rsc)/./app/api/databricks-test/route.ts:25:38)
 ⨯ Error: No response is returned from route handler '/home/slloyd/database_ai_assistant/app/api/databricks-test/route.ts'. Ensure you return a `Response` or a `NextResponse` in all branches of your handler.
    at /home/slloyd/database_ai_assistant/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:53611
    at async e_.execute (/home/slloyd/database_ai_assistant/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:44747)
    at async e_.handle (/home/slloyd/database_ai_assistant/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:54700)
    at async doRender (/home/slloyd/database_ai_assistant/node_modules/next/dist/server/base-server.js:1377:42)
    at async cacheEntry.responseCache.get.routeKind (/home/slloyd/database_ai_assistant/node_modules/next/dist/server/base-server.js:1599:28)
 POST /api/databricks-test 500 in 133ms

The only change made was adding:

webpack: (config) => {
       config.resolve.alias.lz4 = false;
    
       return config;
     },

to my next.config.js to prevent the following error:

Module not found: Can't resolve '../build/Release/xxhash'```
Lenguaje dominante
TypeScript
Estrellas
36
Forks
50
Merge medio
13 h 46 min
PR fusionados (30 d)
9

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de databricks/databricks-sql-nodejs

Todos los issues de databricks/databricks-sql-nodejs

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.