hargata / lubelog

LubeLogger is a web-based vehicle maintenance and fuel mileage tracker
https://lubelogger.com
MIT License
1.15k stars 59 forks source link

[Bug] Divide by Zero exception #121

Closed ethernic closed 10 months ago

ethernic commented 10 months ago

Summary

I mistyped an entry on the fuel tab which now prevents the tab from loading due to a Divide by Zero exception. Other tabs seem unaffected.

Expected Behavior

Semantic input validation should prevent me from adding invalid data, in this case likely a 0 where the field will be used as a divisor.

Current Behavior

I'm not sure the exact data that caused this, but the error indicates a Divide by Zero exception. I'm not familiar with LiteDB so I can't easily check/update the entry.

Logs

lubelogger  | info: Microsoft.Hosting.Lifetime[14]
lubelogger  |       Now listening on: http://[::]:8080
lubelogger  | info: Microsoft.Hosting.Lifetime[0]
lubelogger  |       Application started. Press Ctrl+C to shut down.
lubelogger  | info: Microsoft.Hosting.Lifetime[0]
lubelogger  |       Hosting environment: Production
lubelogger  | info: Microsoft.Hosting.Lifetime[0]
lubelogger  |       Content root path: /App
lubelogger  | fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
lubelogger  |       An unhandled exception has occurred while executing the request.
lubelogger  |       System.DivideByZeroException: Attempted to divide by zero.
lubelogger  |          at System.Decimal.DecCalc.VarDecDiv(DecCalc& d1, DecCalc& d2)
lubelogger  |          at System.Decimal.op_Division(Decimal d1, Decimal d2)
lubelogger  |          at CarCareTracker.Helper.GasHelper.GetGasRecordViewModels(List`1 result, Boolean useMPG, Boolean useUKMPG) in /App/Helper/GasHelper.cs:line 35
lubelogger  |          at CarCareTracker.Controllers.VehicleController.GetReportPartialView(Int32 vehicleId) in /App/Controllers/VehicleController.cs:line 740
lubelogger  |          at lambda_method2(Closure, Object, Object[])
lubelogger  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
lubelogger  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
lubelogger  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
lubelogger  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
lubelogger  |       --- End of stack trace from previous location ---
lubelogger  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
lubelogger  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
lubelogger  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
lubelogger  |       --- End of stack trace from previous location ---
lubelogger  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
lubelogger  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
lubelogger  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
lubelogger  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
lubelogger  |       --- End of stack trace from previous location ---
lubelogger  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
lubelogger  |          at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
lubelogger  |          at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
lubelogger  |          at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.<Invoke>g__Awaited|10_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)
hargata commented 10 months ago

Validation added, bug fixed, it will now skip calculation for per unit fuel consumption if the amount is zero.

Released.

hargata commented 10 months ago

@ethernic this should already be fixed with no detriment to your data, as in you should be able to view and correct the record. Can we close this?

ethernic commented 10 months ago

Yep sorry for the delay. Confirmed this got me back in and I was able to fix the record.