New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid error response for non-existent file #254

nwhitt opened this Issue Sep 6, 2017 · 5 comments


None yet
4 participants
Copy link

nwhitt commented Sep 6, 2017

Issue summary

Attempting to load a non-existent file throws a fatal error instead of a League\Csv\Exception.

System informations

Information Description
League\Csv version 9.0.1
PHP/HHVM version 7.0.22-0ubuntu0.16.04.1
OS Platform ubuntu

Standalone code, or other way to reproduce the problem


Expected result

Similar to Flysystem

File not found at path: /does/not/exist.csv

Actual result

Wrong parameters for League\Csv\Exception([string $message [, long $code [, Throwable $previous = NULL]]])

This comment has been minimized.

Copy link

nyamsprod commented Sep 7, 2017

@nwhitt League CSV and Flysystem are two independent packages so they do not follow the same exception mechanism :) .
Having said that I failed to reproduce your error with you given code I get this:

PHP Fatal error:  Uncaught League\Csv\Exception: fopen(/does/not/exist.csv): failed to open stream: No such file or directory in ....

There's already a test to validate this output in the test suite. Are you sure about the error ? Maybe there's something else at play here

@nyamsprod nyamsprod added the question label Sep 7, 2017


This comment has been minimized.

Copy link

nwhitt commented Sep 7, 2017

It must be in the error handling of my symfony package with suppression, as I get green on unit tests. I'll close this issue until I have more information.


This comment has been minimized.

Copy link

IllyaMoskvin commented Oct 11, 2017

I had this exception happen because the user under which PHP was running (e.g. apache) did not have permissions to do anything except read the target file, which did indeed exist.

I fixed it by adding the 'r' mode to my createFromPath call (cf. fopen mode):

Reader::createFromPath('/file/that/actually/exists.csv', 'r');

I know it's somewhat off-topic, but this issue is the top result in Google for that error message, so maybe this will help someone.


This comment has been minimized.

Copy link

csiszarattila commented Nov 3, 2017

You can reproduce this error if you have a set_error_handler() somewhere in your code.

A custom set_error_handler() emits errors, and error_get_last() returns null, hence the exception throwing not working in this line, it will generate an error:


Lines 177 to 178 in 6418c1c

if (!$resource = @fopen(...$args)) {
throw new Exception(error_get_last()['message']);

The error easily reproducable with this code:

set_error_handler(function($errno, $errstr) {
    var_dump($errno, $errstr);

@fopen("test.cvs", 'r');

--- outputs: 
string(65) "fopen(test.cvs): failed to open stream: No such file or directory"

I think error_get_last()['message'] needs to be checked, and return a general message if its empty.


This comment has been minimized.

Copy link

nyamsprod commented Nov 6, 2017

Good catch this is a easy fix. I'll try to release a patch this week or the next one... or you can submit a PR with the fix if you want

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment