Yii2 console Fatal error: Uncaught exception - yii2

When I enter command yii or test/codeception/bin/yii migrate in the console, receive such a message
Fatal error: Uncaught exception 'yii\base\UnknownPropertyException' with message 'Setting unknown property: yii\console\ErrorHandler::errorAction' in D:\Desktop\loalhost\yii2-wiersz\vendor\yiisoft\yii2\base\Component.php:197
Stack trace:
#0 D:\Desktop\loalhost\yii2-wiersz\vendor\yiisoft\yii2\BaseYii.php(518): yii\base\Component->__set('errorAction', 'site/error')
#1 D:\Desktop\loalhost\yii2-wiersz\vendor\yiisoft\yii2\base\Object.php(105): yii\BaseYii::configure(Object(yii\console\ErrorHandler), Array)
#2 [internal function]: yii\base\Object->__construct(Array)
#3 D:\Desktop\loalhost\yii2-wiersz\vendor\yiisoft\yii2\di\Container.php(372): ReflectionClass->newInstanceArgs(Array)
#4 D:\Desktop\loalhost\yii2-wiersz\vendor\yiisoft\yii2\di\Container.php(151): yii\di\Container->build('yii\\console\\Err...', Array, Array)
#5 D:\Desktop\loalhost\yii2-wiersz\vendor\yiisoft\yii2\BaseYii.php(344): yii\di\Container->get('yii\\console\\Err...', Array, Array)
#6 D:\Desktop\loalhost\yii2-wiersz\vendor\yiisoft\yii2\di\ServiceLocator.php(13 in D:\Desktop\loalhost\yii2-wiersz\vendor\yiisoft\yii2\base\Component.php on line 197
console/config/main.php is default. Problem is on localhost (win7x62) and remote host (debian).
I had the same situation with the attempt to migrate rbac
(yii migrate --migrationPath=#yii/rbac/migrations)
What is causing the problem ??? my ignorance ;)?

Well, as you error message says, you are trying to set unknown property 'errorAction'. I suppose you are using the same error component config here in console app as in web app. See if there is
[
'components' => [
'error' => [
'errorAction' => ...
]
]
]
in your console app config. There shouldn't be 'errorAction'.

Thanks,
I moved from frontend/config and backend/config code
'errorHandler' => [
'errorAction' => 'site/error',
]
to common/config. Frontend and backend app did not have a problem with that, but console yes. After rollback is ok.

Related

yii2-advanced:how can i save image in backend and view that in backend and frontend?

hi i am save image in frontend and that show in frontend true and i test with many way to view that in backend but don't work.
please help me
my controller in backend
Yii::$app->params['uploadPath'] = Yii::getAlias('#frontend') .'/web/uploads/';
$path = Yii::$app->params['uploadPath'] . $model->image_web_filename;
$image->saveAs($path);
url my backend and frontend is seperate
backend:yii.com/:81
frontend:yii.com
i test these soloution but didn't work true:
https://stackoverflow.com/questions/23155428/how-to-get-root-directory-in-yii2
i inset two alias in aliases file in backend\config:
Yii::setAlias('#frontend', 'http://frontend.sample.dev');
Yii::setAlias('#backend', 'http://backend.sample.dev');
and use that in backend/web/index.php
require(__DIR__ . '/../config/aliases.php');
but i get this error:
An Error occurred while handling another error:
exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "site/error".' in
/var/www/blog/vendor/yiisoft/yii2/base/Module.php:532
Stack trace:
#0 /var/www/blog/vendor/yiisoft/yii2/web/ErrorHandler.php(95):
yii\base\Module->runAction('site/error')
#1 /var/www/blog/vendor/yiisoft/yii2/base/ErrorHandler.php(111):
yii\web\ErrorHandler->renderException(Object(yii\web\NotFoundHttpException))
#2 [internal function]: yii\base\ErrorHandler-
>handleException(Object(yii\web\NotFoundHttpException))
#3 {main}
Previous exception:
exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "post/index".' in
/var/www/blog/vendor/yiisoft/yii2/base/Module.php:532
Stack trace:
#0 /var/www/blog/vendor/yiisoft/yii2/web/Application.php(102):
yii\base\Module->runAction('post/index', Array)
#1 /var/www/blog/vendor/yiisoft/yii2/base/Application.php(380):
yii\web\Application->handleRequest(Object(yii\web\Request))
#2 /var/www/blog/backend/web/index.php(18): yii\base\Application->run()
#3 {main}
Next exception 'yii\web\NotFoundHttpException' with message 'Page not
found.' in /var/www/blog/vendor/yiisoft/yii2/web/Application.php:114
Stack trace:
#0 /var/www/blog/vendor/yiisoft/yii2/base/Application.php(380):
yii\web\Application->handleRequest(Object(yii\web\Request))
#1 /var/www/blog/backend/web/index.php(18): yii\base\Application->run()
#2 {main}
i'm pretty late to the party
but i got a few bones to pick with this solution provided.. so here it goes:
you mention you have different front and back configurations
so you are serving different folders for yii.com/:80 and yii.com/:81 respectively /frontend/web and /backend/web.
keeping this in mind,
no amount of aliases can make content of one of them available to the other.
the yii-advanced-app has #frontend and #backend aliases defined in common/config/bootstrap
Yii::setAlias('#common', dirname(__DIR__));
Yii::setAlias('#frontend', dirname(dirname(__DIR__)) . '/frontend');
Yii::setAlias('#backend', dirname(dirname(__DIR__)) . '/backend');
Yii::setAlias('#console', dirname(dirname(__DIR__)) . '/console');
DO NOT CHANGE THESE unless you know very well what you're doing.
Yii is using these aliases to autoload classes defined under these namespaces common, frontend, backend and console. this exact thing is causing the ridiculous chain of "errors occurring while handling other errors"
more details on Yii autloading documentaion
you can simply share content of these folders by creating a symlink from frontend/web/uploads to backend/web/uploads.
your webserver config (or .htaccess) will require the +FollowSymLinks option
Yii can manage this if you add a few lines to the environments/index.php file
'Development' => [
// .. other options
'setWritable' => [
// .. leave the default stuff there
'frontend/web/uploads',
],
'createSymlink' => [
// link => real folder
'backend/web/uploads' => 'frontend/web/uploads',
]
],
'Production' => [
// ..
'setWritable' => [
// ..
'frontend/web/uploads',
],
'createSymlink' => [
// link => real folder
'backend/web/uploads' => 'frontend/web/uploads',
]
],
and then run the init command again, just like in the installation guide (you do have to option to not overwrite local config files)
if you are running under windows, this might now ask you for elevated privileges
php init
or if you chose to make the symlinks manually you can try this quick guide
you can try this solution :
Yii::setAlias('#frontend', 'http://frontend.sample.dev');
Yii::setAlias('#backend', 'http://backend.sample.dev');
and if you upload files in backend set the src parameter of image to
Yii::getAlias('#backend/path/to/your/image/file');
and if you save your files in frontend replace #backend with #frontend
create this function in components folder
namespace common\components;
use Yii;
class Helper extends \yii\web\Request {
public static function getFrontendUrl($path) {
$frontUrl = str_replace('/adminpanel', '', $path);
return $frontUrl;
}
}
and use in backend :
$path \common\components\Helper::getFrontendUrl(Yii::$app->request->baseUrl).$img;
notic: in frontend You do not need

Unable to run console command yii2

I am trying to run yii but unable to this. I am getting following error:
commond : php yii
Exception 'yii\base\UnknownPropertyException' with message 'Setting unknown property: yii\console\Request::parsers'
in /var/www/html/alpha/html/vendor/yiisoft/yii2/base/Component.php:201
Stack trace:
#0 /var/www/html/alpha/html/vendor/yiisoft/yii2/BaseYii.php(529): yii\base\Component->__set('parsers', Array)
#1 /var/www/html/alpha/html/vendor/yiisoft/yii2/base/Object.php(105): yii\BaseYii::configure(Object(yii\console\Request), Array)
#2 [internal function]: yii\base\Object->__construct(Array)
#3 /var/www/html/alpha/html/vendor/yiisoft/yii2/di/Container.php(381): ReflectionClass->newInstanceArgs(Array)
#4 /var/www/html/alpha/html/vendor/yiisoft/yii2/di/Container.php(156): yii\di\Container->build('yii\\console\\Req...', Array, Array)
#5 /var/www/html/alpha/html/vendor/yiisoft/yii2/BaseYii.php(348): yii\di\Container->get('yii\\console\\Req...', Array, Array)
#6 /var/www/html/alpha/html/vendor/yiisoft/yii2/di/ServiceLocator.php(135): yii\BaseYii::createObject(Array)
#7 /var/www/html/alpha/html/vendor/yiisoft/yii2/console/Application.php(219): yii\di\ServiceLocator->get('request')
#8 /var/www/html/alpha/html/vendor/yiisoft/yii2/base/Application.php(380): yii\console\Application->getRequest()
#9 /var/www/html/alpha/html/yii(31): yii\base\Application->run()
#10 {main}
parsers property is available in yii\web\Request, not in yii\console\Request.
Probably you have got your console configuration merged with web configuration where this property is set. If so, make sure console configuration is set with separate request component setup. If this is not the case of configs merge remove this property in console configuration.
It`s work for my issue:
Edit file : console/config/main.php
'components' => [
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'request' => [
'parsers' => new \yii\helpers\UnsetArrayValue(), //Add this line
],
],

Yii2 Errors/No view using AccessControl "as beforeRequest" with custom roles

I use following code:
'as beforeRequest' => [
'class' => 'yii\filters\AccessControl',
'rules' => [
[
'actions' => ['login', 'forgot', 'error'], // guests can just login and nothing else
'allow' => true,
'roles' => ['?'],
],
[
'allow' => true,
'roles' => ['admin', 'access'],
],
],
],
Using this code causes following errors (if a user is logged in, but have not the role admin or access):
An Error occurred while handling another error:
yii\web\ForbiddenHttpException: Sie dürfen diese Aktion nicht durchführen. in /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/filters/AccessControl.php:154
Stack trace:
0 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/filters/AccessControl.php(137): yii\filters\AccessControl->denyAccess(Object(yii\web\User))
1 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/ActionFilter.php(75): yii\filters\AccessControl->beforeAction(Object(yii\web\ErrorAction))
2 [internal function]: yii\base\ActionFilter->beforeFilter(Object(yii\base\ActionEvent))
3 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/Component.php(545): call_user_func(Array, Object(yii\base\ActionEvent))
4 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/Module.php(676): yii\base\Component->trigger('beforeAction', Object(yii\base\ActionEvent))
5 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/Controller.php(144): yii\base\Module->beforeAction(Object(yii\web\ErrorAction))
6 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/Module.php(523): yii\base\Controller->runAction('error', Array)
7 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/web/ErrorHandler.php(97): yii\base\Module->runAction('site/error')
8 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/ErrorHandler.php(111): yii\web\ErrorHandler->renderException(Object(yii\web\ForbiddenHttpException))
9 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\web\ForbiddenHttpException))
10 {main}
Previous exception:
yii\web\ForbiddenHttpException: Sie dürfen diese Aktion nicht durchführen. in /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/filters/AccessControl.php:154
Stack trace:
0 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/filters/AccessControl.php(137): yii\filters\AccessControl->denyAccess(Object(yii\web\User))
1 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/ActionFilter.php(75): yii\filters\AccessControl->beforeAction(Object(yii\base\InlineAction))
2 [internal function]: yii\base\ActionFilter->beforeFilter(Object(yii\base\ActionEvent))
3 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/Component.php(545): call_user_func(Array, Object(yii\base\ActionEvent))
4 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/Module.php(676): yii\base\Component->trigger('beforeAction', Object(yii\base\ActionEvent))
5 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/Controller.php(144): yii\base\Module->beforeAction(Object(yii\base\InlineAction))
6 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/Module.php(523): yii\base\Controller->runAction('', Array)
7 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/web/Application.php(102): yii\base\Module->runAction('', Array)
8 /Applications/XAMPP/xamppfiles/htdocs/cms/vendor/yiisoft/yii2/base/Application.php(380): yii\web\Application->handleRequest(Object(yii\web\Request))
9 /Applications/XAMPP/xamppfiles/htdocs/cms/backend/web/index.php(17): yii\base\Application->run()
10 {main}
If I use ['#'] instead of ['admin', 'access'] it works fine. That means that site/error is rendering probably.
But using ['admin, 'access'] causes errors (in text form) and site/error is NOT rendering probably. Why?
admin is a defined rule and access is a permission. Everything works great using in controllers.
Does anyone have an idea what's wrong here?
Thank you!
It seems that you have an error and the application try to show the error page. But the user don't have access to the error page too.

Logstash Grok filter reading wrong value

I am currently trying to setup some data collections for our app using the full elk stack (Beats - Logstash - ElasticSearch-Kibana). So far everything is working as it should but I have a requirement to capture statistics on the exceptions thrown by the applications (e.g. java.lang.IllegalArgumentException)
I am not really interested in the stack trace itself so I went ahead and added a separate grok filter just for the exception.
Example of Message:
2016-11-15 05:19:28,801 ERROR [App-Initialisation-Thread] appengine.java:520 Failed to initialize external authenticator myapp Support Access || appuser#vm23-13:/mnt/data/install/assembly app-1.4.12#cad85b224cce11eb5defa126030f21fa867b0dad
java.lang.IllegalArgumentException: Could not check if provided root is a directory
at com.myapp.io.AbstractRootPrefixedFileSystem.checkAndGetRoot(AbstractRootPrefixedFileSystem.java:67)
at com.myapp.io.AbstractRootPrefixedFileSystem.<init>(AbstractRootPrefixedFileSystem.java:30)
at com.myapp.io.s3.S3FileSystem.<init>(S3FileSystem.java:32)
at com.myapp.io.s3.S3FileSystemDriver.loadFileSystem(S3FileSystemDriver.java:60)
at com.myapp.io.FileSystems.getFileSystem(FileSystems.java:55)
at com.myapp.authentication.ldap.S3LdapConfigProvider.initializeCloudFS(S3LdapConfigProvider.java:77)
at com.myapp.authentication.ldap.S3LdapConfigProvider.loadS3Config(S3LdapConfigProvider.java:51)
at com.myapp.authentication.ldap.S3LdapConfigProvider.getLdapConfig(S3LdapConfigProvider.java:42)
at com.myapp.authentication.ldap.DelegatingLdapConfigProvider.getLdapConfig(DelegatingLdapConfigProvider.java:45)
at com.myapp.authentication.ldap.LdapExternalAuthenticatorFactory.create(LdapExternalAuthenticatorFactory.java:28)
at com.myapp.authentication.ldap.LdapExternalAuthenticatorFactory.create(LdapExternalAuthenticatorFactory.java:10)
at com.myapp.frob.appengine.getExternalAuthenticators(appengine.java:516)
at com.myapp.frob.appengine.startUp(appengine.java:871)
at com.myapp.frob.appengine.startUp(appengine.java:754)
at com.myapp.jsp.KewServeInitContextListener$1.run(QServerInitContextListener.java:104)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.nio.file.NoSuchFileException: fh-ldap-config/
at com.upplication.s3fs.util.S3Utils.getS3ObjectSummary(S3Utils.java:55)
at com.upplication.s3fs.util.S3Utils.getS3FileAttributes(S3Utils.java:64)
at com.upplication.s3fs.S3FileSystemProvider.readAttributes(S3FileSystemProvider.java:463)
at com.myapp.io.AbstractRootPrefixedFileSystem.checkAndGetRoot(AbstractRootPrefixedFileSystem.java:61)
Example of grok statement:
grok {
patterns_dir => ["./patterns"]
match => ["message", "%{GREEDYDATA}\n%{JAVAFILE:exception}"]
}
Testing on the grok debugger shows correct results:
{
"GREEDYDATA": [
[
"2016-11-15 05:19:28,801 ERROR [App-Initialisation-Thread] appengine.java:520 Failed to initialize external authenticator myapp Support Access || appuser#vm23-13:/mnt/data/install/assembly app-1.4.12#cad85b224cce11eb5defa126030f21fa867b0dad"
]
],
"exception": [
[
"java.lang.IllegalArgumentException"
]
]
}
Problem
When I add the configuration to logstash it captures the Caused string instead of the exception name, even though the "Caused" string is after another new line character. However it works perfectly for other exception messages such as :
016-11-15 06:17:49,691 WARN [SCReplicationWorkerThread-2] ClientJob.java:207 50345 Error communicating to server `199.181.131.249':`80'. Waiting `10' seconds before retrying... If you see this message rarely, the sc will have recovered gracefully. || appuser#vm55-12:/mnt/deployment/install/app app-3.1.23#cad85b224cce11eb5defa126030f21fa867b0dad
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.net.SocketInputStream.read(SocketInputStream.java:223)
at java.io.DataInputStream.readBoolean(DataInputStream.java:242)
at com.myapp.replication.client.ClientJob.passCheckRevision(ClientJob.java:279)
at com.myapp.replication.client.ClientJob.execute(ClientJob.java:167)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:534)
Any advice would be appreciated.
Thanks
Did you setting the mutiline in the input or filebeat input ,
like this to show the pattern start with ISO8601
I think maybe you mutiline not fetch the whole line
input {
beats {
port => 5044
codec => multiline {
pattern => "^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}[\.,][0-9]{3,7} "
negate => true
what => "previous"
}
}
}

Kohana throws errors while adding filter to routes

I'm using Kohana framework v3.3.1. Here's the default route in my bootstrap.php,
Route::set('default', '(<controller>(/<action>(/<id>)))')
->filter(
function(\Route $route, $params, \Request $request) {
$params['action'] = str_replace('-', '_', $params['action']);
return $params;
}
)
->defaults(array(
'controller' => 'home',
'action' => 'index',
));
Whenever I add "filter" to the route, I get the following error,
Fatal error: Uncaught Kohana_Exception [ 0 ]: Invalid Route::callback specified ~ SYSPATH/classes/Kohana/Route.php [ 391 ] thrown in /system/classes/Kohana/Route.php on line 391
The same code works fine in my localhost (ubuntu 14.04) but doesn't work in Bluehost. Any help would be greatly appreciated.
Figured it out. Though bluehost implements PHP v5.4, code corresponding to v5.2 only works.
Route::set('testing', 'foo')
->filter(array('Class', 'method_to_process_my_uri'));
Reference: Kohana v3.3 User Guide