1602 / 1602/jugglingdb

It is impossible to use this.errors.add(attr, message) in a Model Callback

Abierto
#219 9 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
JavaScript
Estrellas
2k
Forks
238
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

for example for "beforeCreate" callback you should invoke "this.isValid()" to make
" this.errors.add(attr, message)" works as expected(but it works if you have at least one model validation).

The main reason of such error is validatable.js.
in the "isValid" method it set correct initial value for errors:

Object.defineProperty(this, 'errors', {
enumerable: false,
configurable: true,
value: new Errors
});

But in the "cleanErrors" method it set boolean value instead of "new Error":

```
Object.defineProperty(inst, 'errors', {
enumerable: false,
configurable: true,
value: false
});
```

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Look at the validatable.js file, specifically the 'isValid' and 'cleanErrors' methods. The bug is that 'cleanErrors' sets errors to a boolean instead of a new Errors instance. Start by understanding the model callback flow (like beforeCreate) and how errors are managed. Write a test to reproduce the issue where this.errors.add fails in a callback without prior validation. Check if there are existing tests for model validation or callbacks to see the expected behavior.

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

Evaluación

Stack tecnológico
javascript, nodejs
Área
backend, databases
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.