Skip to content
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

Fatal error rgument 1 passed to Davaxi\\Sparkline::setLineColorHex() must be of the type string when comparing #18534

Closed
tsteur opened this issue Dec 23, 2021 · 7 comments · Fixed by #18588 or #18696
Labels
Potential Bug Something that might be a bug, but needs validation and confirmation it can be reproduced. Regression Indicates a feature used to work in a certain way but it no longer does even though it should.
Milestone

Comments

@tsteur
Copy link
Member

tsteur commented Dec 23, 2021

See below error. seems this happened when comparing? A segment is applied too but could be removed when reproducing I would assume.

Error: {"message":"Argument 1 passed to Davaxi\Sparkline::setLineColorHex() must be of the type string, null given, called in /core/Visualization/Sparkline.php on line 189","file":"/vendor/davaxi/sparkline/src/Sparkline/StyleTrait.php","line":74,"request_id":"b59e6","backtrace":" on /vendor/davaxi/sparkline/src/Sparkline/StyleTrait.php(74)\n#0 /core/Visualization/Sparkline.php(189): Davaxi\Sparkline->setLineColorHex(NULL, 1)\n#1 /core/Visualization/Sparkline.php(106): Piwik\Visualization\Sparkline->setSparklineColors(Object(Davaxi\Sparkline), 1)\n#2 /plugins/CoreVisualizations/Visualizations/Sparkline.php(105): Piwik\Visualization\Sparkline->main()\n#3 /core/Plugin/Report.php(320): Piwik\Plugins\CoreVisualizations\Visualizations\Sparkline->render()\n#4 /plugins/CoreHome/Controller.php(61): Piwik\Plugin\Report->render()\n#5 [internal function]: Piwik\Plugins\CoreHome\Controller->renderReportWidget(Object(Piwik\Plugins\VisitFrequency\Reports\Get))\n#6 /core/FrontController.php(619): call_user_func_array(Array, Array)\n#7 /core/FrontController.php(168): Piwik\FrontController->doDispatch('VisitFrequency', 'get', Array)\n#8 /core/dispatch.php(32): Piwik\FrontController->dispatch()\n#9 /index.php(25): require_once('/c...')\n#10 {main}","safemode_backtrace":"#0 [internal function]: Piwik\Plugins\Cloud\Controller->safemode(Array)\n#1 /core/FrontController.php(619): call_user_func_array(Array, Array)\n#2 /core/FrontController.php(168): Piwik\FrontController->doDispatch('Cloud', 'safemode', Array)\n#3 /core/FrontController.php(99): Piwik\FrontController->dispatch('CorePluginsAdmi...', 'safemode', Array)\n#4 /core/FrontController.php(139): Piwik\FrontController::(Array)\n#5 /core/FrontController.php(189): Piwik\FrontController::(Object(TypeError))\n#6 /core/dispatch.php(32): Piwik\FrontController->dispatch()\n#7 /index.php(25): require_once('/c...')\n#8 {main}"}

URL: https://example.matomo.org/index.php?forceView=1&viewDataTable=sparkline&module=VisitFrequency&action=get&idSite=1&period=year&date=2021-01-01,2021-12-31&segment=userId=@test&comparePeriods[]=year&compareDates[]=2020-01-01&compareSegments=&showtitle=1&random=159&columns=nb_actions_returning&colors=%7B%22backgroundColor%22%3A%22%23ffffff%22%2C%22lineColor%22%3A%5B%22%23558b2f%22%2Cnull%5D%2C%22minPointColor%22%3A%22%23ff7f7f%22%2C%22maxPointColor%22%3A%22%2375bf7c%22%2C%22lastPointColor%22%3A%22%2355aaff%22%2C%22fillColor%22%3A%22%23ffffff%22%7D

Referrer: https://example.matomo.org/index.php?module=CoreHome&action=index&idSite=1&period=day&date=yesterday

GET: {"forceView":"1","viewDataTable":"sparkline","module":"VisitFrequency","action":"get","idSite":"1","period":"year","date":"2021-01-01,2021-12-31","segment":"userId=@test","comparePeriods":["year"],"compareDates":["2020-01-01"],"compareSegments":"","showtitle":"1","random":"159","columns":"nb_actions_returning","colors":"{"backgroundColor":"#ffffff","lineColor":["#558b2f",null],"minPointColor":"#ff7f7f","maxPointColor":"#75bf7c","lastPointColor":"#55aaff","fillColor":"#ffffff"}"}

@tsteur tsteur added the Potential Bug Something that might be a bug, but needs validation and confirmation it can be reproduced. label Dec 23, 2021
@sgiehl
Copy link
Member

sgiehl commented Dec 23, 2021

This could possibly be a vue migration issue. It seems for some reason the sparkline uses null as second series color.
See

var comparisonService = piwikHelper.getAngularDependency('piwikComparisonsService');
if (comparisonService.isComparing()) {
var comparisons = comparisonService.getAllComparisonSeries();
colors.lineColor = comparisons.map(function (comp) { return comp.color; });
}

and
getAllComparisonSeries(): ComparisonSeriesInfo[] {
const seriesInfo: ComparisonSeriesInfo[] = [];
let seriesIndex = 0;
this.getPeriodComparisons().forEach((periodComp) => {
this.getSegmentComparisons().forEach((segmentComp) => {
seriesInfo.push({
index: seriesIndex,
params: { ...segmentComp.params, ...periodComp.params },
color: this.colors[`series${seriesIndex}`],
});
seriesIndex += 1;
});
});
return seriesInfo;
}

Could you have a quick look if that's a regression? @diosmosis

@diosmosis
Copy link
Member

I'm not able to reproduce. If null is being used, then it is coming from ColorManager not the comparison service (if the color wasn't there in the comparison service, we'd get undefined). The best change I could come up with is: #18536 in case it's a race condition of some kind.

@tsteur
Copy link
Member Author

tsteur commented Dec 31, 2021

Also getting similar fatal errors for a different method. This one I can reproduce on our own instance.

Error: {"message":"Argument 1 passed to Davaxi\Sparkline::setBackgroundColorHex() must be of the type string, null given, called in /core/Visualization/Sparkline.php on line 183","file":"/vendor/davaxi/sparkline/src/Sparkline/StyleTrait.php","line":54,"request_id":"57701","backtrace":" on /vendor/davaxi/sparkline/src/Sparkline/StyleTrait.php(54)\n#0 /core/Visualization/Sparkline.php(183): Davaxi\Sparkline->setBackgroundColorHex(NULL)\n#1 /core/Visualization/Sparkline.php(106): Piwik\Visualization\Sparkline->setSparklineColors(Object(Davaxi\Sparkline), 0)\n#2 /plugins/CoreVisualizations/Visualizations/Sparkline.php(105): Piwik\Visualization\Sparkline->main()\n#3 /core/Plugin/Report.php(320): Piwik\Plugins\CoreVisualizations\Visualizations\Sparkline->render()\n#4 /plugins/CoreHome/Controller.php(61): Piwik\Plugin\Report->render()\n#5 [internal function]: Piwik\Plugins\CoreHome\Controller->renderReportWidget(Object(Piwik\Plugins\API\Reports\Get))\n#6 /core/FrontController.php(619): call_user_func_array(Array, Array)\n#7 /core/FrontController.php(168): Piwik\FrontController->doDispatch('API', 'get', Array)\n#8 /core/dispatch.php(32): Piwik\FrontController->dispatch()\n#9 /index.php(25): require_once('/c...')\n#10 {main}","safemode_backtrace":"#0 [internal function]: Piwik\Plugins\Cloud\Controller->safemode(Array)\n#1 /core/FrontController.php(619): call_user_func_array(Array, Array)\n#2 /core/FrontController.php(168): Piwik\FrontController->doDispatch('Cloud', 'safemode', Array)\n#3 /core/FrontController.php(99): Piwik\FrontController->dispatch('CorePluginsAdmi...', 'safemode', Array)\n#4 /core/FrontController.php(139): Piwik\FrontController::(Array)\n#5 /core/FrontController.php(189): Piwik\FrontController::(Object(TypeError))\n#6 /core/dispatch.php(32): Piwik\FrontController->dispatch()\n#7 /index.php(25): require_once('/c...')\n#8 {main}"}

URL: https://example.matomo.org/index.php?date=2021-11-30,2021-12-29&forceView=1&viewDataTable=sparkline&module=API&action=get&disableLink=0&widget=1&idSite=1&period=day&columns=nb_visits%2Cnb_uniq_visitors&colors=%7B%22lineColor%22%3A%22%23cac5be%22%2C%22minPointColor%22%3A%22%23ff7272%22%2C%22maxPointColor%22%3A%22%237cc282%22%2C%22lastPointColor%22%3A%22%2355b3ff%22%7D

Referrer: https://example.matomo.org/index.php?module=CoreHome&action=index&idSite=1&period=day&date=yesterday

GET: {"date":"2021-11-30,2021-12-29","forceView":"1","viewDataTable":"sparkline","module":"API","action":"get","disableLink":"0","widget":"1","idSite":"1","period":"day","columns":"nb_visits,nb_uniq_visitors","colors":"{"lineColor":"#cac5be","minPointColor":"#ff7272","maxPointColor":"#7cc282","lastPointColor":"#55b3ff"}"}

@tsteur tsteur added the Regression Indicates a feature used to work in a certain way but it no longer does even though it should. label Dec 31, 2021
@tsteur tsteur added this to the 4.7.0 milestone Dec 31, 2021
@tsteur
Copy link
Member Author

tsteur commented Dec 31, 2021

not sure if related, also seeing such a notice
image

@tsteur
Copy link
Member Author

tsteur commented Dec 31, 2021

It doesn't look vue related. Quick fix might be in PHP to default the missing/incorrect colors

@sgiehl sgiehl self-assigned this Jan 7, 2022
@tsteur tsteur reopened this Jan 27, 2022
@tsteur
Copy link
Member Author

tsteur commented Jan 27, 2022

We have applied this fix on production but the errors are still happening.

Error: {"message":"Davaxi\Sparkline::setBackgroundColorHex(): Argument #1 ($color) must be of type string, null given, called in /core/Visualization/Sparkline.php on line 185","file":"/vendor/davaxi/sparkline/src/Sparkline/StyleTrait.php","line":54,"request_id":"007b6","backtrace":" on /vendor/davaxi/sparkline/src/Sparkline/StyleTrait.php(54)\n#0 /core/Visualization/Sparkline.php(185): Davaxi\Sparkline->setBackgroundColorHex(NULL)\n#1 /core/Visualization/Sparkline.php(106): Piwik\Visualization\Sparkline->setSparklineColors(Object(Davaxi\Sparkline), 0)\n#2 /plugins/CoreVisualizations/Visualizations/Sparkline.php(105): Piwik\Visualization\Sparkline->main()\n#3 /core/Plugin/Controller.php(257): Piwik\Plugins\CoreVisualizations\Visualizations\Sparkline->render()\n#4 /plugins/MultiSites/Controller.php(119): Piwik\Plugin\Controller->renderView(Object(Piwik\Plugins\CoreVisualizations\Visualizations\Sparkline))\n#5 [internal function]: Piwik\Plugins\MultiSites\Controller->getEvolutionGraph()\n#6 /core/FrontController.php(619): call_user_func_array(Array, Array)\n#7 /core/FrontController.php(168): Piwik\FrontController->doDispatch('MultiSites', 'getEvolutionGra...', Array)\n#8 /core/dispatch.php(32):

URL: https://example.matomo.org/index.php?module=MultiSites&action=getEvolutionGraph&period=day&date=2021-12-23,2022-01-21&evolutionBy=nb_visits&columns=nb_visits&idSite=4&idsite=4&viewDataTable=sparkline&colors=%7B%22lineColor%22%3A%22%23cac5be%22%2C%22minPointColor%22%3A%22%23ff7272%22%2C%22maxPointColor%22%3A%22%237cc282%22%2C%22lastPointColor%22%3A%22%2355b3ff%22%7D

Referrer: https://example.matomo.org/index.php?module=MultiSites&action=index&idSite=1&period=day&date=yesterday

@tsteur
Copy link
Member Author

tsteur commented Jan 27, 2022

I can also reproduce this locally and something like below fixed it for me

diff --git a/core/Visualization/Sparkline.php b/core/Visualization/Sparkline.php
index e3cff4fb11..c960dea8eb 100644
--- a/core/Visualization/Sparkline.php
+++ b/core/Visualization/Sparkline.php
@@ -179,6 +179,8 @@ class Sparkline implements ViewInterface
 
         if (empty($colors)) { // quick fix so row evolution sparklines will have color in widgetize's iframes
             $colors = $defaultColors;
+        } else {
+            $colors = array_merge($defaultColors, $colors);
         }
 
         if (strtolower($colors['backgroundColor']) !== '#ffffff') {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Potential Bug Something that might be a bug, but needs validation and confirmation it can be reproduced. Regression Indicates a feature used to work in a certain way but it no longer does even though it should.
Projects
None yet
3 participants