Flutter - Async file reading exception handling - flutter

I am new to dart/flutter and a litte confused by the async-await flutter exception handling in this case.
So basically i have this function that loads a .json settings file from the flutter data folder.
Its supposed to load the settings and throw a SettingsLoadingException in the case it's unable to find the file, so the calling function knows when to create a new one.
This mechanism works, but two things are confusing me in this case. First of all it's still printing an uncaught FileSystemException to the console even though the print "No settings file!" shows it got caught. Secondly "No settings file" and the error are printed twice - so is it catching two errors?
Future<Settings> loadSettings() async {
try {
String fileName = SettingsService.settingsFileName;
File file = File("${await _localPath}/${dbFolderName}/${fileName}");
String fileContent = await file.readAsString();
Map<String, dynamic> settingJsonMap = jsonDecode(fileContent);
Settings settings = Settings.fromJson(settingJsonMap);
return settings;
} catch (e) {
print("No settings file!");
throw SettingsLoadingException("Unable to load settings");
}
}
I/flutter (10533): No settings file!
I/flutter (10533): No settings file!
E/flutter (10533): \[ERROR:flutter/runtime/dart_vm_initializer.cc(41)\] Unhandled Exception: FileSystemException: Cannot open file, path = '/data/user/0/com.yapps.smartdart/app_flutter/db/settings.json' (OS Error: No such file or directory, errno = 2)
E/flutter (10533): #0 \_File.open.\<anonymous closure\> (dart:io/file_impl.dart:356:9)
E/flutter (10533): \<asynchronous suspension\>
E/flutter (10533):
E/flutter (10533): \[ERROR:flutter/runtime/dart_vm_initializer.cc(41)\] Unhandled Exception: FileSystemException: Cannot open file, path = '/data/user/0/com.yapps.smartdart/app_flutter/db/settings.json' (OS Error: No such file or directory, errno = 2)
E/flutter (10533): #0 \_File.open.\<anonymous closure\> (dart:io/file_impl.dart:356:9)
E/flutter (10533): \<asynchronous suspension\>
E/flutter (10533):
E/SurfaceSyncer(10533): Failed to find sync for id=0
W/Parcel (10533): Expecting binder but got null!
I already tried using the .then and .catchError API which didn't work and led me to a totally different error.

The first thing you're confused about, FileSystemException is an error on the native side of the plugin you're using. So don't worry about that. the error is just getting caught on the plugin side and so does the error message that is being printed.
And The second thing which is messages getting printed twice should not have anything to do with the FileSystemException. My guess is you're calling the method twice. If so, you can confirm this by running this code in debug mode and using break points

Related

How to read files outside the project's directory

I'm new to flutter,I want to read some files outide the directory of my flutter project,let's say a file located in Desktop folder
here's how I tried
Future<File> _getLocalFile() async {
return File('/Users/xxx/Desktop/test.txt');
}
then I got this error
[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: FileSystemException: Cannot open file, path = '/Users/xxx/Desktop/test.txt' (OS Error: Operation not permitted, errno = 1)
Is there any way I can get the permission to deal with such files?

Zend - Fatal error: Uncaught Zend_View_Exception: script '/.phtml'

Get the following error message on my app. The app is written with the Zend framework, but not by myself. Can anyone tell me what the error message says.
It is about an extra module after all and a template file is missing. Is that correct so far? Can I just copy it in there myself?
Fatal error: Uncaught Zend_View_Exception: script '/.phtml' not found in path
(/application/modules/default/views/scripts/) in
/library/Zend/View/Abstract.php:987 Stack trace: #0
/library/Zend/View/Abstract.php(883): Zend_View_Abstract->_script('/.phtml')
#1 /library/Zend/Controller/Action/Helper/ViewRenderer.php(910):
Zend_View_Abstract->render('/.phtml') #2
library/Zend/Controller/Action/Helper/ViewRenderer.php(931):
Zend_Controller_Action_Helper_ViewRenderer->renderScript('/.phtml', NULL) #3
library/Zend/Controller/Action/Helper/ViewRenderer.php(970):
Zend_Controller_Action_Helper_ViewRenderer->render() #4
/libr in
library/Zend/Controller/Plugin/Broker.php on line 335
Would be very grateful for any tip.
Greetz Bavra

Flutter widget test error: OS Error: Read-only file system, errno = 30

when I use “flutter run xxx_test.dart”, I got an error:
I/flutter (15574): The following FileSystemException was thrown
running a test:
I/flutter (15574): Creation failed, path = '//.test' (OS Error:
Read-only file system, errno = 30)
since I call function:
dir.createSync(recursive: true);
how to resolve it? thx

FPDF works locally but not online

I have a FPDF output which works perfectly locally but there is problem online.
The error is:
Fatal error: Uncaught exception 'Exception' with message 'FPDF error: Some data has already been output, can't send PDF file (output started at /home/wa/public_html/razpis/baza.inc.php:1)' in /home/wa/public_html/razpis/fpdf.php:271
Stack trace:
#0 /home/wa/public_html/razpis/fpdf.php(1052): FPDF->Error('Some data has a...')
#1 /home/wa/public_html/razpis/fpdf.php(1012): FPDF->_checkoutput()
#2 /home/wa/public_html/razpis/naredipdf.php(169): FPDF->Output('razpis.pdf', 'D')
#3 /home/wa/public_html/razpis/razpis5.php(136): require('/home/wa...')
#4 /home/wa/public_html/razpis/index.php(165): include_once('/home/wa...')
#5 {main} thrown in /home/wa/public_html/razpis/fpdf.php on line 271

Zend Session saves in the right path, but gc try to clean elsewhere

My Project is running under ZF 1.11, and it throws this error randomly:
Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'Zend_Session::start() - /home/user/www/MyProject/library/Zend/Session.php(Line:469): Error #8 session_start() [<a href='function.session-start'>function.session-start</a>]: ps_files_cleanup_dir: opendir(/tmp) failed: Permission denied (13) Array' in /home/user/www/MyProject/library/Zend/Session.php:482 Stack trace:
#0 /home/user/www/MyProject/library/Zend/Session/Namespace.php(143): Zend_Session::start(true)
#1 /home/user/www/MyProject/library/Dlx/Acl/Permissao.php(8): Zend_Session_Namespace->__construct('user_info')
#2 /home/user/www/MyProject/application/Bootstrap.php(72): Dlx_Acl_Permissao->__construct(Object(Zend_Db_Adapter_Pdo_Mysql))
#3 /home/user/www/MyProject/library/Zend/Application/Bootstrap/BootstrapAbstract.php(669): Bootstrap->_initLoaders()
#4 /home/user/www/MyProject/library/Zend/Application/Bootstrap/BootstrapAbstract.php(622): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('loaders')
#5 /home/user/ in /home/user/www/MyProject/library/Zend/Session.php on line 482
As you can see, it tries to clean the session in /tmp directory, but in my application.ini the configuration sets session.save_path to APPLICATION_PATH "/../data/session" (ZF default conf), and it saves the session in this path, but when gc runs, it tries to clean in the wrong directory
This is my application.ini session configuration:
http://codepad.org/mJUyipG0
Btw, /data and /data/session permission are set to 777
Any ideas ?
Check your php.ini /tmp seems top be the default directory for php session saves. Although in my installation the save path line is commented out. ;session.save_path = "/tmp"
You can also debug by dumping Zend_Session::getOptions(); (it is a static method) to make sure your parameters are being correctly set.
This might be the cause of the exception:
string save_path - The correct value is system dependent, and should
be provided by the developer using an absolute path to a directory
readable and writable by the PHP process. If a writable path is not
supplied, then Zend_Session will throw an exception when started
(i.e., when start() is called).
Hopefully it's this simple, just supply an absolute path and check permissions.
The .. in the path may be the problem. APPLICATION_PATH "/../data/session"