skip to Main Content

I’m encountering an error during the deployment of my Firebase functions. The error message I’m receiving is:

"Error: Functions codebase could not be analyzed successfully. It may have a syntax or runtime error."

I have reviewed my code and ensured that there are no syntax errors. However, the error persists. I have also checked the necessary API requirements and they are enabled.

I would appreciate any insights or suggestions on how to resolve this issue. Please find below the relevant code snippet:


export const readTarjeta = functions.storage.object().onFinalize(async (object) => {
    const imageBucket = `gs://${object.bucket}/${object.name}`;
    const client = new vision.ImageAnnotatorClient();

    const [textDetection] = await client.textDetection(imageBucket);
    const [annotation] = textDetection.textAnnotations;
    const text = annotation ? annotation.description : "";
    logger.log(text);

   const re = /(.*)//;
   const uid = re.exec(object.name)[1];

  const regexArray = [
    // /(?<=PROPIETARIO?)s*(.*)n/,
    /bJ[a-zA-Z0-9]{6}b/gm,
    /(?<=MODELO)s*(.*)n/,
    /[a-zA-Z0-9]{17}$n/gm,
];

let regExpSalto = /propietario:s*n/i;

 let propietario;
 let placasJ;
 let marcaJ;
 let anio;
 let modeloJ;
 let motorJ;
 let nivJ;
 
    if(regExpSalto.test(text)){
        let regExpBajo = /propietario:s*ns*((w+s){3,4})s+/i;
        if(regExpBajo.test(text)){
            let matches2 = text.match(regExpBajo);
            if(matches2){
                  propietario = matches2[1];
            }
        }else{

            let a = "Propietario:\s+"
            let b = "(( +\w+){3,5}\s*\n)"
            let saltoLinea = ".+\s+"
            let saltoLinea2 = "";
            
            
            let tes = "";
            let testeo = new RegExp();
            let condicion;

            let i = 0;

            while(!condicion && i <= 7){
                saltoLinea2 += saltoLinea;

                tes = a+saltoLinea2+b;
                testeo = RegExp(tes,"i")
                condicion = testeo.test(text)
                
                let matches = text.match(testeo);

                    if(matches){
                         propietario = matches[1];
                        
                    }
                i++;
            }
        }
    }else{
        let regExp = /PROPIETARIO:s*([^nr]+)/;
        let matches = text.match(regExp);
        if(matches){
              propietario = matches[1];
              
        }else{
            propietario = "no se encontro el nombre del propietario"
        }
    }

    let regExpModelo = /s+(d{4})n/;
    let matchesModelo = text.match(regExpModelo);
    if (matchesModelo) {
        anio = matchesModelo[1];
    } else {
        anio = "No se encontró el modelo del vehiculo";
    }

    let regExpPlacas = /s(w{3}d{3,4})n/;
    let matchesPlacas = text.match(regExpPlacas);
    if (matchesPlacas) {
        placasJ = matchesPlacas[1];
    } else {
        placasJ = "No se encontraron las placas del vehículo";
    }

        marcaJ = todasLasMarcas.find((marca) => {
          const regexMarca = new RegExp(`^\s*\b${marca}\b`, 'im');
            return regexMarca.test(text);
          });
          
          if (!marcaJ) {
            marcaJ = "No se encontró la marca";
          }
          
        const lineas = text.split('n').slice(7); 

        modeloJ = todosLosModelos.find((modelo) => {
            const regexModelo = new RegExp(`^\s*\b${modelo}\b`, 'im');
            return lineas.some((linea) => regexModelo.test(linea));
          });
        
          if (!modeloJ) {
            modeloJ = "No se encontró el modelo";
          }



            const regexMotor = /[NUM]*[No.]*s*MOTOR:s*([w-]{5,20})/i;
            const matchMotor = text.match(regexMotor);

            if (matchMotor) {
                const numeroMotor = matchMotor[1];
                motorJ = numeroMotor;
            } else {
                motorJ = "No se encontró el número de motor en el texto";
            }

            let regexpNiv = /b[A-HJ-NPR-Z0-9]{17}b/i; //Omite O, Q y I
            let matchesNiv = text.match(regexpNiv);
            if (matchesNiv) {
                nivJ = matchesNiv[0];
                
            } else {
                nivJ="No se encontraron coincidencias para el NIV";
            }

const fields = {
  // owner: "",
  // placas: "",
  // modelo: "",
  // serie: "",
};

for (let i = 0; i < regexArray.length; i++) {
  const regex = regexArray[i];
  const match = text.match(regex);
  if (match) {
      const fieldName = Object.keys(fields)[i];
      fields[fieldName] = match[0]?.trim()?.replace(/^(w+:)s*/, '');
  }
}
const car ={
  owner: propietario,
  placas: placasJ,
  serie: nivJ, // Use serie or modelo if serie is not found
  year: anio,
  brand: marcaJ,
  model: modeloJ,
  motor: motorJ,
  isConfirmed: false,
  userUid:uid,
  imageBucket
}

  logger.log(car)

  admin.firestore().collection("Cars").add(car);
  logger.log(car);
})

Thank you in advance for any assistance you can provide!

I have double-checked my code for any syntax errors or runtime issues, but couldn’t find any. Is there any other possible cause for this error? How can I resolve it and successfully deploy my Firebase Functions?

Any insights or suggestions would be greatly appreciated. Thank you!

2

Answers


  1. So the error could be just about anything.
    For example you could be having a permissioning error based on your rules.

    There is a way to get the exact error message out and that is by using the --debug parameter when deploying.

    The full command to use is:

    firebase deploy --only functions --debug
    

    Using this you can hopefully get out the exact problem which should point you in the right direction.

    Login or Signup to reply.
  2. You can also find the error this way:

    1. Run the `firebase emulators:start’ command
    2. When functions fails to start, a new file called firebase-debug.log will be created at the root of your project
    3. Open the firebase-debug.log file and scroll down to the bottom
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search