Browse Source

Log better errors.

pull/473/head
James Cole 2 years ago
parent
commit
a1545df4fc
No known key found for this signature in database GPG Key ID: B49A324B7EAD6D80
  1. 5
      .ci/phpstan.neon
  2. 2
      app/Console/Commands/AutoImport.php
  3. 2
      app/Console/Commands/Import.php
  4. 2
      app/Console/Commands/ShowVersion.php
  5. 4
      app/Console/Commands/UpgradeImportConfigurations.php
  6. 2
      app/Console/VerifyJSON.php
  7. 7
      app/Http/Controllers/AutoImportController.php
  8. 2
      app/Http/Controllers/AutoUploadController.php
  9. 4
      app/Http/Controllers/DebugController.php
  10. 45
      app/Http/Controllers/Import/ConversionController.php
  11. 53
      app/Http/Controllers/Import/File/RoleController.php
  12. 6
      app/Http/Controllers/Import/MapController.php
  13. 2
      app/Http/Controllers/Import/Nordigen/LinkController.php
  14. 4
      app/Http/Controllers/Import/Nordigen/SelectionController.php
  15. 2
      app/Http/Controllers/Import/Spectre/ConnectionController.php
  16. 9
      app/Http/Controllers/Import/UploadController.php
  17. 34
      app/Http/Middleware/IsReadyForStep.php

5
.ci/phpstan.neon

@ -6,7 +6,10 @@ parameters:
checkGenericClassInNonGenericObjectType: false # remove this rule when all other issues are solved.
ignoreErrors:
# TODO: slowly remove these exceptions and fix the issues found.
- '#Control structures using switch should not be used#'
- '#is not allowed to extend#' # don't care.
- '#is neither abstract nor final#' # don't care
- '#with null as default value#' # don't care
- '#Function compact\(\) should not be used.#' # don't care
paths:
- ../app
- ../database

2
app/Console/Commands/AutoImport.php

@ -33,7 +33,7 @@ use Illuminate\Console\Command;
/**
* Class AutoImport
*/
class AutoImport extends Command
final class AutoImport extends Command
{
use AutoImports;
use HaveAccess;

2
app/Console/Commands/Import.php

@ -35,7 +35,7 @@ use Illuminate\Console\Command;
/**
* Class Import
*/
class Import extends Command
final class Import extends Command
{
use AutoImports;
use HaveAccess;

2
app/Console/Commands/ShowVersion.php

@ -29,7 +29,7 @@ use Illuminate\Console\Command;
/**
* Class ShowVersion
*/
class ShowVersion extends Command
final class ShowVersion extends Command
{
/**
* The console command description.

4
app/Console/Commands/UpgradeImportConfigurations.php

@ -32,7 +32,7 @@ use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use SplFileInfo;
class UpgradeImportConfigurations extends Command
final class UpgradeImportConfigurations extends Command
{
/**
* The console command description.
@ -64,7 +64,7 @@ class UpgradeImportConfigurations extends Command
*/
public function handle(): int
{
$directory = (string)$this->argument('directory');
$directory = (string)$this->argument('directory'); // @phpstan-ignore-line
if (!file_exists($directory)) {
$this->error(sprintf('"%s" does not exist.', $directory));

2
app/Console/VerifyJSON.php

@ -43,7 +43,7 @@ trait VerifyJSON
$json = file_get_contents($file);
try {
json_decode($json, true, 512, JSON_THROW_ON_ERROR);
} catch (Exception|JsonException $e) {
} catch (JsonException $e) {
$message = sprintf('The importer can\'t import: could not decode the JSON in the config file: %s', $e->getMessage());
app('log')->error($message);

7
app/Http/Controllers/AutoImportController.php

@ -85,7 +85,7 @@ class AutoImportController extends Controller
$this->importFiles($directory, $files);
} catch (ImporterErrorException $e) {
app('log')->error($e->getMessage());
throw new ImporterErrorException(sprintf('Import exception (see the logs): %s', $e->getMessage()));
throw new ImporterErrorException(sprintf('Import exception (see the logs): %s', $e->getMessage()), 0, $e);
}
return response('');
@ -100,6 +100,11 @@ class AutoImportController extends Controller
$this->line($string);
}
/**
* @param string $string
*
* @return void
*/
public function line(string $string)
{
echo sprintf("%s: %s\n", date('Y-m-d H:i:s'), $string);

2
app/Http/Controllers/AutoUploadController.php

@ -72,7 +72,7 @@ class AutoUploadController extends Controller
$json = $request->file('json');
// TODO update documentation to document rename of importable file variable.
$importable = $request->file('importable');
$importablePath = $importable?->getPathname();
$importablePath = (string) $importable?->getPathname();
try {
$this->importUpload($json->getPathname(), $importablePath);

4
app/Http/Controllers/DebugController.php

@ -114,7 +114,7 @@ class DebugController extends Controller
$system = $this->getSystemInfo();
$app = $this->getAppInfo();
$user = $this->getUserInfo();
$table = (string)view('debug-table', compact('system', 'app', 'user'))->render();
$table = view('debug-table', compact('system', 'app', 'user'))->render();
return str_replace(["\n", "\t", ' '], '', $table);
}
@ -124,7 +124,7 @@ class DebugController extends Controller
$baseBuild = null;
$isDocker = env('IS_DOCKER', false);
if ($isDocker) {
if (true === $isDocker) {
if (file_exists('/var/www/counter-main.txt')) {
$build = trim(file_get_contents('/var/www/counter-main.txt'));
}

45
app/Http/Controllers/Import/ConversionController.php

@ -97,6 +97,7 @@ class ConversionController extends Controller
// job ID may be in session:
$identifier = session()->get(Constants::CONVERSION_JOB_IDENTIFIER);
$routine = null;
$flow = $configuration->getFlow();
app('log')->debug('Will redirect to submission after conversion.');
$nextUrl = route('008-submit.index');
@ -108,17 +109,13 @@ class ConversionController extends Controller
/** @var RoutineManagerInterface $routine */
if ('file' === $flow) {
$contentType = $configuration->getContentType();
switch ($contentType) {
default:
case 'unknown':
case 'csv':
app('log')->debug('Create CSV routine manager.');
$routine = new CSVRoutineManager($identifier);
break;
case 'camt':
app('log')->debug('Create CAMT routine manager.');
$routine = new CAMTRoutineManager($identifier);
break;
if ('unknown' === $contentType || 'csv' === $contentType) {
app('log')->debug('Create CSV routine manager.');
$routine = new CSVRoutineManager($identifier);
}
if ('camt' === $contentType) {
app('log')->debug('Create CAMT routine manager.');
$routine = new CAMTRoutineManager($identifier);
}
}
if ('nordigen' === $flow) {
@ -133,6 +130,9 @@ class ConversionController extends Controller
app('log')->debug('Will redirect to mapping after conversion.');
$nextUrl = route('006-mapping.index');
}
if (null === $routine) {
throw new ImporterErrorException(sprintf('Could not create routine manager for flow "%s"', $flow));
}
// may be a new identifier! Yay!
$identifier = $routine->getIdentifier();
@ -147,7 +147,7 @@ class ConversionController extends Controller
}
/**
* @param Request $request
* @param Request $request
*
* @return JsonResponse
* @throws ImporterErrorException
@ -160,6 +160,7 @@ class ConversionController extends Controller
app('log')->debug(sprintf('Now at %s', __METHOD__));
$identifier = $request->get('identifier');
$configuration = $this->restoreConfiguration();
$routine = null;
// now create the right class:
$flow = $configuration->getFlow();
@ -169,15 +170,11 @@ class ConversionController extends Controller
/** @var RoutineManagerInterface $routine */
if ('file' === $flow) {
$contentType = $configuration->getContentType();
switch ($contentType) {
default:
case 'unknown':
case 'csv':
$routine = new CSVRoutineManager($identifier);
break;
case 'camt':
$routine = new CAMTRoutineManager($identifier); // why do we need this one?
break;
if ('unknown' === $contentType || 'csv' === $contentType) {
$routine = new CSVRoutineManager($identifier);
}
if ('camt' === $contentType) {
$routine = new CAMTRoutineManager($identifier); // why do we need this one?
}
}
if ('nordigen' === $flow) {
@ -187,6 +184,10 @@ class ConversionController extends Controller
$routine = new SpectreRoutineManager($identifier);
}
if (null === $routine) {
throw new ImporterErrorException(sprintf('Could not create routine manager for flow "%s"', $flow));
}
$importJobStatus = RoutineStatusManager::startOrFindConversion($identifier);
RoutineStatusManager::setConversionStatus(ConversionStatus::CONVERSION_RUNNING);
@ -235,7 +236,7 @@ class ConversionController extends Controller
}
/**
* @param Request $request
* @param Request $request
*
* @return JsonResponse
*/

53
app/Http/Controllers/Import/File/RoleController.php

@ -62,7 +62,7 @@ class RoleController extends Controller
}
/**
* @param Request $request
* @param Request $request
*
* @return View|void
* @throws JsonException
@ -84,18 +84,18 @@ class RoleController extends Controller
$configuration = $this->restoreConfiguration();
$contentType = $configuration->getContentType();
switch ($contentType) {
default:
throw new ImporterErrorException(sprintf('Cannot handle file type "%s"', $contentType));
case 'csv':
return $this->csvIndex($request, $configuration);
case 'camt':
return $this->camtIndex($request, $configuration);
if ('csv' === $contentType) {
return $this->csvIndex($request, $configuration);
}
if ('camt' === $contentType) {
return $this->camtIndex($request, $configuration);
}
throw new ImporterErrorException(sprintf('Cannot handle file type "%s"', $contentType));
}
/**
* @param RolesPostRequest $request
* @param RolesPostRequest $request
*
* @return RedirectResponse
* @throws ContainerExceptionInterface
@ -110,21 +110,20 @@ class RoleController extends Controller
$configuration = $this->restoreConfiguration();
$contentType = $configuration->getContentType();
switch ($contentType) {
default:
throw new ImporterErrorException(sprintf('Cannot handle file type "%s" in POST.', $contentType));
case 'csv':
return $this->csvPostIndex($request, $configuration);
case 'camt':
return $this->camtPostIndex($request, $configuration);
//return $this->camtPostIndex($request, $configuration);
if ('csv' === $contentType) {
return $this->csvPostIndex($request, $configuration);
}
if ('camt' === $contentType) {
return $this->camtPostIndex($request, $configuration);
}
throw new ImporterErrorException(sprintf('Cannot handle file type "%s" in POST.', $contentType));
}
/**
* @param Request $request
* @param Configuration $configuration
* @param Request $request
* @param Configuration $configuration
*
* @return View
* @throws ContainerExceptionInterface
@ -219,8 +218,8 @@ class RoleController extends Controller
/**
* TODO is basically the same as the CSV processor.
*
* @param RolesPostRequest $request
* @param Configuration $configuration
* @param RolesPostRequest $request
* @param Configuration $configuration
*
* @return RedirectResponse
* @throws ContainerExceptionInterface
@ -264,8 +263,8 @@ class RoleController extends Controller
}
/**
* @param Request $request
* @param Configuration $configuration
* @param Request $request
* @param Configuration $configuration
*
* @return View
* @throws ContainerExceptionInterface
@ -303,8 +302,8 @@ class RoleController extends Controller
}
/**
* @param RolesPostRequest $request
* @param Configuration $configuration
* @param RolesPostRequest $request
* @param Configuration $configuration
*
* @return RedirectResponse
* @throws ContainerExceptionInterface
@ -347,7 +346,7 @@ class RoleController extends Controller
}
/**
* @param string $level
* @param string $level
*
* @return array
*/
@ -367,7 +366,7 @@ class RoleController extends Controller
/**
* Will tell you if any role needs mapping.
*
* @param array $array
* @param array $array
*
* @return bool
*/

6
app/Http/Controllers/Import/MapController.php

@ -366,13 +366,13 @@ class MapController extends Controller
app('log')->debug(sprintf('[%s/%s] Parsing transaction (2)', ($index + 1), $total));
/** @var array $row */
foreach ($transaction['transactions'] as $row) {
$categories[] = (string)array_key_exists('category_name', $row) ? $row['category_name'] : '';
$categories[] = (string)(array_key_exists('category_name', $row) ? $row['category_name'] : '');
}
}
$filtered = array_filter(
$categories,
static function (?string $value) {
return '' !== (string)$value;
static function (string $value) {
return '' !== $value;
}
);

2
app/Http/Controllers/Import/Nordigen/LinkController.php

@ -95,7 +95,7 @@ class LinkController extends Controller
return redirect(route('004-configure.index'));
}
$uuid = (string)Uuid::uuid4()->toString();
$uuid = Uuid::uuid4()->toString();
$url = config('nordigen.url');
$accessToken = TokenManager::getAccessToken();

4
app/Http/Controllers/Import/Nordigen/SelectionController.php

@ -105,7 +105,7 @@ class SelectionController extends Controller
}
if ($response instanceof ErrorResponse) {
throw new ImporterErrorException((string)$response->message);
throw new ImporterErrorException($response->message);
}
return view('import.009-selection.index', compact('mainTitle', 'subTitle', 'response', 'countries', 'configuration'));
@ -128,7 +128,7 @@ class SelectionController extends Controller
$values = $request->getAll();
// overrule with sandbox?
if (config('nordigen.use_sandbox')) {
if (true === config('nordigen.use_sandbox')) {
$values['bank'] = 'SANDBOXFINANCE_SFIN0000';
}

2
app/Http/Controllers/Import/Spectre/ConnectionController.php

@ -130,7 +130,7 @@ class ConnectionController extends Controller
app('log')->debug('About to get connections.');
$request = new ListConnectionsRequest($url, $appId, $secret);
$request->customer = (string)$identifier;
$request->customer = $identifier;
$list = $request->get();
if ($list instanceof ErrorResponse) {

9
app/Http/Controllers/Import/UploadController.php

@ -118,7 +118,9 @@ class UploadController extends Controller
$errors = $this->processUploadedFile($flow, $errors, $importedFile);
// process config file (if present)
$errors = $this->processConfigFile($errors, $configFile);
if (0 === count($errors) && null !== $configFile) {
$errors = $this->processConfigFile($errors, $configFile);
}
// process pre-selected file (if present):
$errors = $this->processSelection($errors, (string)$request->get('existing_config'), $configFile);
@ -201,11 +203,8 @@ class UploadController extends Controller
* @return MessageBag
* @throws ImporterErrorException
*/
private function processConfigFile(MessageBag $errors, UploadedFile|null $file): MessageBag
private function processConfigFile(MessageBag $errors, UploadedFile $file): MessageBag
{
if (count($errors) > 0 || null === $file) {
return $errors;
}
app('log')->debug('Config file is present.');
$errorNumber = $file->getError();
if (0 !== $errorNumber) {

34
app/Http/Middleware/IsReadyForStep.php

@ -41,11 +41,13 @@ trait IsReadyForStep
public const TEST = 'test';
/**
* @param Request $request
* @param Closure $next
* @param Request $request
* @param Closure $next
*
* @return mixed
* @throws ContainerExceptionInterface
* @throws ImporterErrorException
* @throws NotFoundExceptionInterface
*/
public function handle(Request $request, Closure $next): mixed
{
@ -62,7 +64,7 @@ trait IsReadyForStep
}
/**
* @param Request $request
* @param Request $request
*
* @return bool
* @throws ContainerExceptionInterface
@ -84,25 +86,17 @@ trait IsReadyForStep
return $result;
}
if ('nordigen' === $flow) {
$result = $this->isReadyForNordigenStep();
//app('log')->debug(sprintf('isReadyForNordigenStep: Return %s', var_export($result, true)));
return $result;
return $this->isReadyForNordigenStep();
}
if ('spectre' === $flow) {
$result = $this->isReadyForSpectreStep();
//app('log')->debug(sprintf('isReadyForSpectreStep: Return %s', var_export($result, true)));
return $result;
return $this->isReadyForSpectreStep();
}
return $this->isReadyForBasicStep();
}
/**
* @param Request $request
* @param Request $request
*
* @return RedirectResponse|null
* @throws ContainerExceptionInterface
@ -113,7 +107,7 @@ trait IsReadyForStep
{
$flow = $request->cookie(Constants::FLOW_COOKIE);
if (null === $flow) {
app('log')->debug('redirectToCorrectStep returns true because $flow is null');
app('log')->debug('redirectToCorrectStep returns NULL because $flow is null');
return null;
}
@ -137,12 +131,12 @@ trait IsReadyForStep
private function isReadyForBasicStep(): bool
{
app('log')->debug(sprintf('isReadyForBasicStep("%s")', self::STEP));
switch (self::STEP) {
default:
throw new ImporterErrorException(sprintf('isReadyForBasicStep: Cannot handle basic step "%s"', self::STEP));
case 'service-validation':
return true;
if (self::STEP === 'service-validation') {
return true;
}
throw new ImporterErrorException(sprintf('isReadyForBasicStep: Cannot handle basic step "%s"', self::STEP));
}
/**

Loading…
Cancel
Save